Copy code The code is as follows:
function strSplit($s, $len) {
$end = '...';
$result = '';
$strLen = strlen($s);
if ($strLen <= $len) {
return $s;
}
$len -= 2;
for ($i=0; $i<$len && $i<$strLen; $i++) {
$c = $s[$i];
if (ord( $c) < 0x80) {
$result .= $c;
} elseif ($i+1<$len) {
$result .= $s[$i++] . $s[ $i];
}
}
return ($i < $strLen) ? ($result . $end) : $result;
}
echo strSplit(' 1234567', 10), '
';
echo strSplit('1234567890', 10), '
'; ), '
';
echo strSplit('All are in Chinese', 10), '
';
echo strSplit('All a and b are c d中文', 10), '
';
Output:
1234567
1234567890
1234 Chinese...
All are...
All a and all b...
http://www.bkjia.com/PHPjc/317788.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/317788.htmlTechArticleCopy the code The code is as follows: functionsstrSplit($s,$len){ $end='…'; $result= ''; $strLen=strlen($s); if($strLen=$len){ return$s; } $len-=2; for($i=0;$i$len$i$strLen;$i++ ){ $c=$s[$i];...