感兴趣
PHP比较好用的字符串
截取函数的小伙伴,下面一起跟随编程之家 jb51.cc的小编来看看吧。
# 编程之家 (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);
// 输出