UTF8下面截取中文字符。

简介:这是UTF-8下面截取中文字符。的详细页面,介绍了和php,有关的知识、技巧、经验,和一些php源码等。

class='pingjiaF' frameborder='0' src='http://biancheng.dnbcw.info/pingjia.php?id=329774' scrolling='no'>
<?php
//支持中文的substr(string,length[,start])
//“反斜杠”被博客系统过滤了,请在每个 x 前面添加“反斜杠”
function cnsubstr($l1,$l2,$l3=0){
    $I2 = "/[x01-x7f]|[xc2-xdf][x80-xbf]|xe0[xa0-xbf][x80-xbf]|[xe1-xef][x80-xbf][x80-xbf]|xf0[x90-xbf][x80-xbf][x80-xbf]|[xf1-xf7][x80-xbf][x80-xbf][x80-xbf]/";
    preg_match_all($I2,$l1,$I3);
       if (count($I3[0]) - $l3 > $l2) {
           return implode('',array_slice($I3[0],$l3,$l2))."...";
       }
       return implode('',array_slice($I3[0],$l3,$l2));
}
//计算中文字符长度
function len($l1){
    $I2 = "/[x01-x7f]|[xc2-xdf][x80-xbf]|xe0[xa0-xbf][x80-xbf]|[xe1-xef][x80-xbf][x80-xbf]|xf0[x90-xbf][x80-xbf][x80-xbf]|[xf1-xf7][x80-xbf][x80-xbf][x80-xbf]/";
    preg_match_all($I2,$l1,$I3);
       return count($I3[0]);
}
?>

“UTF-8下面截取中文字符。”的更多相关文章 》

爱J2EE关注Java迈克尔杰克逊视频站JSON在线工具

http://biancheng.dnbcw.info/php/329774.html pageNo:12
原文地址:https://www.cnblogs.com/ooooo/p/2250794.html