我也来一个
支持中英文混合、左、右截取
<?php
//left左侧截取,right右侧截取
//作者:ISLET
function left($content,$length) {
if($length && strlen($content)>$length){
$num=0;
for($i=0;$i<$length-3;$i++) {
if(ord($content[$i])>127){
$num++;
}
}
$num%2==1 ? $content=substr($content,0,$length-4):$content=substr($content,0,$length-3);
$content.='..';
}
return $content;
}
function right($content,$length) {
if($length && strlen($content)>$length){
$len=strlen($content);
$s=$len-$length;
$num=0;
for($i=$s;$i<$len;$i++) {
if(ord($content[$i])>127){
$num++;
}
}
$num%2==1 ? $content=substr($content,$s+1,$length):$content=substr($content,$s+2,$length);
$content='..'.$content;
}
return $content;
}
?>