将中文字符串分割为数组 解决str_split中文乱码php
首先来介绍str_split()这个函数;
它的作用是将字符串分割为数组;
例如:
$str='abcde';
str_plite($str);
打印结果如下:
Array
(
[0] => a
[1] => b
[2] => c
[3] => d
[4] => e
)
看似很好用的样子;但是作为中国程序员;不可避免的要和中文打交道;
这时候再用str_splite就会悲剧的发现乱码了;;;
不要怕;preg_splite可以拯救这个问题;
当然是需要配合正则使用的;
/**
* 将字符串分割为数组
* @param string $str 字符串
* @return array 分割得到的数组
*/
function mb_str_split($str){
return preg_split('/(?<!^)(?!$)/u', $str );
}
$str='白俊遥博客';
mb_str_split($str);
打印结果如下:
Array
(
[0] => 白
[1] => 俊
[2] => 遥
[3] => 博
[4] => 客
)
打完;收工;
---------------------
作者:白俊遥
来源:CSDN
原文:https://blog.csdn.net/bai9474500755/article/details/51059520
版权声明:本文为博主原创文章,转载请附上博文链接!
将中文字符串分割为数组 解决str_split中文乱码php的更多相关文章
- php - 中文字符串分割
//先删除掉非中文的字体$str = preg_replace('/[^\x{4e00}-\x{9fa5}]/u', '', $str);//经过测试中文占3个篇幅$re = chunk_split( ...
- oracle根据分隔符将字符串分割成数组函数
--创建表类型 create or replace type mytype as table of number;--如果定义成varchar--CREATE OR REPLACE type myty ...
- shell 将字符串分割成数组
代码:test.sh #!/bin/bash a="one,two,three,four" #要将$a分割开,可以这样: OLD_IFS="$IFS" IFS= ...
- Linux shell 将字符串分割成数组
原文链接:http://1985wanggang.blog.163.com/blog/static/776383320121745626320/ a="one,two,three,four& ...
- 【Linux】shell字符串分割、数组访问、条件判断
参考资料: shell字符串分割再循环:http://www.shangxueba.com/jingyan/1633455.html linux shell中 if else以及大于.小于.等于逻辑表 ...
- [转+整理]linux shell 将字符串分割成数组
原文链接:http://1985wanggang.blog.163.com/blog/static/776383320121745626320/ a="one,two,three,four& ...
- c#中文字符串与byte数组互相转化
因为中文字符串一个字符占两个字节,所以不能用正常的方式与byte之间进行互相转化 中文字符串转成byte[] byte[] ping = Encoding.UTF8.GetBytes("你的 ...
- 字符串---分割成数组(str_split ),算出一个字符串中出现最多的字符, 学校中最多的姓名
split 分割separate分开 little 小的 echo '<meta http-equiv="Content-type" content="text/h ...
- 字符串分割与数组的分割 split()VSsplice()&slice()
一.作用对象 1.split()方法是对字符串的操作:splice()和slice()是对数组的操作.slice()也可用于字符串. 二.参数 1.split(separator,howmany) 参 ...
随机推荐
- Gym 101149L Right Build
L. Right Build time limit per test 2.0 s memory limit per test 256 MB input standard input output st ...
- js中parseInt和Number
昨天在项目中遇到一个问题,有关字符串准换成数字的问题,具体如下: 页面中<input type="number" id="bankNum" ng-mode ...
- 在Web根目录下建立testdb.php文件内容
apache_2.0.50-win32-x86-no_ssl.msi php-5.0.0-Win32.zipmysql-4.0.20d-win.zipphpMyAdmin-2.5.7.zip 操作系统 ...
- datagrid---columns列
{ field:"city", //字段名,从后台传来的要一致 title:"城市",//列的标题文字. width:,//列的宽度 formatter:fun ...
- [No0000100]正则表达式匹配解析过程分析(正则表达式匹配原理)&regexbuddy使用&正则优化
常见正则表达式引擎引擎决定了正则表达式匹配方法及内部搜索过程,了解它至关重要的.目前主要流行引擎有:DFA,NFA两种引擎. 引擎 区别点 DFA Deterministic finite autom ...
- 知识驱动对话-Learning to Select Knowledge for Response Generation in Dialog Systems-阅读笔记
今日看了一篇文章<Learning to Select Knowledge for Response Generation in Dialog Systems>,以知识信息.对话目标.对话 ...
- Java NIO 读取文件、写入文件、读取写入混合
前言 Java NIO(new/inputstream outputstream)使用通道.缓冲来操作流,所以要深刻理解这些概念,尤其是,缓冲中的数据结构(当前位置(position).限制(limi ...
- href='#' 和 href='###'
如果想定义一个空的链接,又不跳转到页面头部,可以写href="###". 详细解释就是'#' 是有特定意义的,如果 '#' 后有内容会被认为是一个标签而从页面找到相应标签跳转到该处 ...
- hive分析nginx日志之UDF清洗数据
hive分析nginx日志一:http://www.cnblogs.com/wcwen1990/p/7066230.html hive分析nginx日志二:http://www.cnblogs.com ...
- 免费SSL证书Let's Encrypt(certbot)安装使用教程
免费SSL证书Let's Encrypt(certbot)安装使用教程 https://www.vpser.net/build/letsencrypt-certbot.html