Home  >  Article  >  Backend Development  >  Chinese partner English lines function to solve the problem of Chinese and English string length

Chinese partner English lines function to solve the problem of Chinese and English string length

WBOY
WBOYOriginal
2016-07-29 08:36:131365browse

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.


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn