时时商务社区
标题:
使用php实现截取指定长度
[打印本页]
作者:
网络通达
时间:
2018-2-14 08:12
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字符串截取的简单方法
欢迎光临 时时商务社区 (http://bbs.4435.cn/)
Powered by Discuz! X3.2