网上的方法都是先用ord判断,判断是属于汉字还是数字还是字母。
然后用substr截取。
实际可以用内置的函数截取,
<?php
$str = '我住在3号楼A座';
$list = array();
$start = 0;
$lengh = mb_strlen($str,'utf8');//这里可以是指定的长度
while (count($list)<$lengh) {
$list[] = mb_substr($str, $start,1,'utf8');//也可以用$list .=
$start++;
}
print_r($list);
?>
mb系列函数有少数的环境没有,需要自己开启
然后用substr截取。
实际可以用内置的函数截取,
<?php
$str = '我住在3号楼A座';
$list = array();
$start = 0;
$lengh = mb_strlen($str,'utf8');//这里可以是指定的长度
while (count($list)<$lengh) {
$list[] = mb_substr($str, $start,1,'utf8');//也可以用$list .=
$start++;
}
print_r($list);
?>
mb系列函数有少数的环境没有,需要自己开启
NET 正则里有个\G 这样解释的
\G 的 MSDN解释:指定匹配必须出现在上一个匹配结束的地方。与 Match.NextMatch() 一起使用时,此断言确保所有匹配都是连续的。
效果http://blog.csdn.net/q107770540/article/details/6436973
print_r(preg_split('##u', $str, -1, PREG_SPLIT_NO_EMPTY));你看这个行不行?
楼主是在介绍中文字符串截取的方法,并非是要拆分字符串为数组
$str = '我住在3号楼A座';
mb_internal_encoding("gbk");
echo mb_substr($str, 0, 5);iconv_set_encoding("internal_encoding", "gbk");
echo iconv_substr($str, 0, 5);
然后用substr截取。
实际可以用内置的函数截取我想,他说的很清楚了。只是举例容易让人....