欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

PHP按字符串长度分割成数组,支持中文

程序员文章站 2024-01-04 11:23:58
...

PHP按字符串长度分割成数组,支持中文 http://blog.ppsql.net/post-1843.html 无 ?php function str_split_unicode($str, $l = 0) { if ($l 0) { $ret = array(); $len = mb_strlen($str, "UTF-8"); for ($i = 0; $i $len; $i += $l) { $ret[] = mb_substr($st

PHP按字符串长度分割成数组,支持中文
http://blog.ppsql.net/post-1843.html
 0) {
         $ret = array();
         $len = mb_strlen($str, "UTF-8");
         for ($i = 0; $i 
 $s = "还未如愿sss见gfg者不rtret不朽"; // Mild milk
 print_r(str_split($s, 5));
 print_r(str_split_unicode($s, 5));
 
 //输出
 //Array ( [0] => 还?? [1] => ?如? [2] => ??sss [3] => 见gf [4] => g者? [5] => ??rtr [6] => et不 [7] => 朽 )
 //Array ( [0] => 还未如愿s [1] => ss见gf [2] => g者不rt [3] => ret不朽 )
http://blog.ppsql.net/post-1843.html

上一篇:

下一篇: