时间:2021-07-01 10:21:17 帮助过:6人阅读
function cutstr_html($string,$length=0,$ellipsis='…'){
$string=strip_tags($string);
$string=preg_replace('/\n/is','',$string);
$string=preg_replace('/ | /is','',$string);
$string=preg_replace('/ /is','',$string);
preg_match_all("/[\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]/",$string,$string);
if(is_array($string)&&!empty($string[0])){
if(is_numeric($length)&&$length){
$string=join('',array_slice($string[0],0,$length)).$ellipsis;
}else{
$string=implode('',$string[0]);
}
}else{
$string='';
}
return $string;
}