时间:2016-02-16 19:40 来源: 我爱IT技术网 作者:佚名
欢迎您访问我爱IT技术网,今天小编为你分享的电脑教程之dedeCMS系列教程:【dedecms重新定义cn_substr函数截取字数更准确】,请阅读以下详细内容!
dedecms重新定义cn_substr函数截取字数更准确
if ( ! function_exists(‘cn_substr’)){
function cn_substr($str, $cutLen, $oDot=null, $hasHtml=false, $cutSlashes=false, $addSlashes=false) {
global $cfg_soft_lang;
$str=trim ( $str );
if ($cutSlashes) $str=stripslashes ( $str );
if($hasHtml){
$str=preg_replace ( “/(\<[^\<]*\>|\r|\n|\s|\[.+?\])/is”, ‘ ‘, $str );
$str=htmlspecialchars ( $str );
}else{
$str=htmlspecialchars ( $str );
}
if ($cutLen && strlen ( $str ) > $cutLen) {
$nStr=”;
if ($cfg_soft_lang==‘utf-8′) {
$n=0;
$tn=0;
$noc=0;
while ( $n < strlen ( $str ) ) {
$t=ord ( $str [$n] );
if ($t==9 || $t==10 || (32 <=$t && $t <=126)) {
$tn=1;
$n ++;
$noc ++;
} elseif (194 <=$t && $t <=223) {
$tn=2;
$n +=2;
$noc +=2;
} elseif (224 <=$t && $t < 239) {
$tn=3;
$n +=3;
$noc +=2;
} elseif (240 <=$t && $t <=247) {
$tn=4;
$n +=4;
$noc +=2;
} elseif (248 <=$t && $t <=251) {
$tn=5;
$n +=5;
$noc +=2;
} elseif ($t==252 || $t==253) {
$tn=6;
$n +=6;
$noc +=2;
} else {
$n ++;
}
if ($noc >=$cutLen)break;
}
if ($noc > $cutLen) $n -=$tn;
$nStr=substr ( $str, 0, $n );
} else {
for($i=0; $i < $cutLen – 1; $i ++) {
if (ord ( $str [$i] ) > 127) {
$nStr .=$str [$i] . $str [$i + 1];
$i ++;
} else {
$nStr .=$str [$i];
}
}
}
$str=$nStr . $oDot;
}
if ($addSlashes) $str=addslashes ( $str );
$str=htmlspecialchars_decode ( $str );
return trim ( $str );
}
}
关于dedecms重新定义cn_substr函数截取字数更准确的用户互动如下:
相关问题:
答: >>详细
相关问题:
答: >>详细
相关问题:
答: >>详细
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
