# 编程之家 (jb51.cc)
function sysSubStr($string,$length,$append = false)
{
if(strlen($string) <= $length )
{
return $string;
}
else
{
$i = 0;
while ($i < $length)
{
$stringTMP = substr($string,$i,1);
if ( ord($stringTMP) >=224 )
{
$stringTMP = substr($string,3);
$i = $i + 3;
}
elseif( ord($stringTMP) >=192 )
{
$stringTMP = substr($string,2);
$i = $i + 2;
}
else
{
$i = $i + 1;
}
$stringLast[] = $stringTMP;
}
$stringLast = implode("",$stringLast);
if($append)
{
$stringLast .= "...";
}
return $stringLast;
}
}
$string = "专注于互联网主流的各种技术";
$length = "27";
$append = true;
echo sysSubStr($string,$append);
// 输出
原文链接:https://www.f2er.com/php/527871.html