The phpmb_substr function intercepts Chinese characters. The php mb_substr function intercepts the first two and the last two characters of a variable. the variable content is a Chinese character, but only the first two characters can be output, the last two characters cannot be output. Does the mb_substr function not support truncation from the end? Also, give pointers.
$ Ip = "Foshan Telecom, Guangdong province ";
Echo mb_substr ($ ip, 0, 2, 'utf-8 ');
Echo mb_substr ($ ip,-2, 'utf-8 ');
?>
Current output: Guangdong
Expected Output: Guangdong Telecom
Thank you!
Reply to discussion (solution)
The second sentence should report an error.
String mb_substr (string $ str, int $ start [, int $ length [, string $ encoding])
The second parameter is length.
The maximum number of characters to use in str.
Mb_internal_encoding ("UTF-8 ");
$ Ip = "Foshan Telecom, Guangdong province ";
Echo mb_substr ($ ip, 0, 2 );
Echo mb_substr ($ ip,-2 );
Dizzy, I saw you in PPC too ..
The problem is quite tangled. $ Chinese characters and spaces must be considered in ip strings. spaces are considered only one length. Therefore, it is not feasible to use strlen to determine the character length and then intercept the character.