Home >Backend Development >PHP Tutorial >Chinese partner English lines function to solve the problem of Chinese and English string length
Copy the codeThe code is as follows:
function strSplit($s, $len) {
$end = '...';
$result = '';
$strLen = strlen($s);
if ($ Strlen & LT; = $ Len) {
Return $ s;
}
$ len- = 2;
for ($ i = 0; $ & lt; $ len & & lt; $ strlen; c = $s[$i];
$result .= $s [$i++].$s[$i];
, '
';
echo strSplit('1234567890', 10), '
';
echo strSplit('1234中文567890abcdefghijkl', 10), '
';
echo strSplit('All are in Chinese', 10), '
';
echo strSplit('All a, b, c are d Chinese', 10), '
';
Output:
1234567
1234567890
1234 Chinese...
All are...
All a and all b...
The above has introduced the function of solving the Chinese and English string length problem of Chinese partners' English lines, including the content of Chinese partners' English lines. I hope it will be helpful to friends who are interested in PHP tutorials.