|
PHP语言: 根据中文裁减字符串
[U]复制代码[/U] 代码如下:
function cutstr($string,$length, $dot = ' ...') {
if (strlen($string) '),array($pre . '&'. $end, $pre . '"' . $end, $pre . '' . $end), $string);
$strcut = '';
if (strtolower(CHARSET) == 'utf-8'){
$n = $tn =$noc = 0;
while ($n= $length){
break;
}
}
if ($noc> $length) {
$n -= $tn;
}
$strcut =substr($string, 0, $n);
} else {
for ($i =0; $i 127 ? $string[$i] . $string[++$i] : $string[$i];
}
}
$strcut = str_replace(array($pre . '&' .$end, $pre . '"' . $end, $pre . '' .$end), array('&', '"',''), $strcut);
$pos = strrpos($strcut, chr(1));
if ($pos !== false) {
$strcut =substr($strcut, 0, $pos);
}
return $strcut . $dot;
}
您可能感兴趣的文章:PHP 截取字符串函数整理(支持gb2312和utf-8)PHP 截取字符串专题集合php字符串截取的简单方法
|
|