The most accurate PHP intercept string length function, intercept string
Said is the most accurate interception length, in fact, I am not sure whether it is the most accurate, specific how accurate to see the following effect will know:
First, the string for the test:
<?php header ("Content-type:text/html;charset=utf-8"); echo Cn_substr_utf8 (' I am a, and Ha, OH also,, country! ', 12); Echo '
', Cn_substr_utf8 (' ai\ ' 2145m a CH3 me [is a, a, and Ha, OH also,, country! ', 12); Echo '
', Cn_substr_utf8 (' I, is a, a, and Ha, OH also,, country! ', 12); Echo '
', Cn_substr_utf8 (' I am a, a, and Ha, OH also,, country! ', 12); Echo '
', Cn_substr_utf8 (' I am, one, one, and Ha, OH also,, country! ', 12); Echo '
', Cn_substr_utf8 (' I, yes, one, one, and Ha, OH also,, country! ', 12); Echo '
', Cn_substr_utf8 (' I am asd one, one, and Ha, OH also,, country! ', 12); Echo '
', Cn_substr_utf8 (' I i\ ' m[is a, a, and Ha, OH also,, country! ', 12); Echo '
', Cn_substr_utf8 (' I\ ' m a ch me [is a, a, and Ha, OH also,, country! ', 12); Echo '
Here is the exact intercept of the string:
The specific function code is as follows:
Utf-8 Chinese intercept, single byte intercept mode function Cn_substr_utf8 ($STR, $length, $append = ' ... ', $start =0) { if (strlen ($STR) < $start + 1) { return '; } Preg_match_all ("/./su", $str, $ar); $str 2= '; $tstr = "; Www.phpernote.com for ($i =0;isset ($ar [0][$i]), $i + +) { if (strlen ($TSTR) < $start) { $tstr. = $ar [0][$ I]; } else{ if (strlen ($str 2) < $length + strlen ($ar [0][$i]) { $str 2.= $ar [0][$i]; } else{break;}}}
If you think it's not accurate, you can improve on this basis, or innovation, I hope this article about the PHP interception of string length function is helpful to everyone's learning.
http://www.bkjia.com/PHPjc/1066508.html www.bkjia.com true http://www.bkjia.com/PHPjc/1066508.html techarticle The most accurate PHP intercept string length function, intercept the string is said to be the most accurate interception length, in fact, I am not sure whether it is the most accurate, specific how accurate to see the following effect on the know ...