支持中文的PHP按字符串长度分割成数组代码,_PHP教程
程序员文章站
2022-05-13 09:21:35
...
支持中文的PHP按字符串长度分割成数组代码,
以下是我编写的代码,实现对中英文混杂字符进行分割:
'; print_r($r); echo ''; ?>
运行结果:
Array ( [0] => 我爱北京 [1] => 3我爱上 [2] => 海-我爱 [3] => xian [4] => ggan [5] => g )
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不朽 )
以上所述就是本文的全部内容了,希望大家能够喜欢。