-
- function toFixLen($str,$len){ //Interception of fixed-length string
- if($len>=strlen($str)||!$len)return$str;
- $len-=3;
- $tempstr1=substr($str,0,$len); //Intercept string
- $tempstr2=preg_replace('/([x81-xff]+)$/ms','' ,$tempstr1,1); //Remove the consecutive Chinese characters at the end
- if(!is_int((strlen($tempstr1)-strlen($tempstr2))/2)){ //The removed characters are an odd number?
- $tempstr1 =substr($str,0,$len-1);
- }
- return$tempstr1."…";
- }
- ?>
Copy code
|