/ *
* Can avoid garbled interception Chinese characters
* Parameters $ STR is a string, $ start is the start character, $ LEN end characters
* Returns the character after interception
* /
Function Msubstr ($ STR, $ START, $ LEN) {
$ tmpstr = ""
$ Strlen = $ start $ LEN;
For ($ I = 0; $ I <$ Strlen; $ I ) {
IF (Substr ($ Str, $ I, 1)> 0xA0) {
$ Tmpstr. = Substr ($ STR, $ I, 2);
$ i ;
Else
$ Tmpstr. = SUBSTR ($ STR, $ I, 1);
}
Return $ TMPSTR;
}
?>
php / * # $ start is the starting position, the default is 0 # $ LEN to intercept the length, if you encounter half of the Chinese characters, automatically reduce the length instead of taking the whole Chinese characters, guarantees the length of the specified * / function Substr_cn ($ Str, $ LEN, $ START = 0) {$ Strlen = Strlen ($ Str); for ($ I = 0; $ Strlen; $ I ) {IF ($ I> = $ Start && $ I <($ START $ LEN) {IF (Substr ($ Str, $ I, 1))> 0xA1) {$ Tmpstr. = Substr ($ STR, $ I, 2); $ I ;} else $ TMPSTR = SUBSTR ($ STR, $ I, 1);}}} (Strlen ($ tmpstr)> $ LEN) {$ Len -; Return Substr_CN ($ Str, $ LEN, $ START);} Return $ TMPSTR; }
/ / -------------------------------------------------------------------------------------------- - // Example Echo Substr_CN ("123AS China PHP Alliance", 9, 1); Echo "
"; Echo Substr_CN ("123AS China PHP Alliance", 10);
?>