mengdejun 发表于 2013-1-28 09:44:28

UTF-8下面截取中文字符。

<?php//支持中文的substr(string,length[,start])//“反斜杠”被博客系统过滤了,请在每个 x 前面添加“反斜杠”function cnsubstr($l1,$l2,$l3=0){    $I2 = "/||xe0||xf0|/";    preg_match_all($I2,$l1,$I3);       if (count($I3) - $l3 > $l2) {         return implode('',array_slice($I3,$l3,$l2))."...";       }       return implode('',array_slice($I3,$l3,$l2));}//计算中文字符长度function len($l1){    $I2 = "/||xe0||xf0|/";    preg_match_all($I2,$l1,$I3);       return count($I3);}?> 
页: [1]
查看完整版本: UTF-8下面截取中文字符。