PHP has a lot of ways of handling strings , and tonight we've chosen a very representative and widely used function to explain that the word
character string Split function:mb_substr (), I hope you will recognize really learn Learning Comprehension!
Mb_substr () has a few parameters, usually 3 or 4 parameters, we especially say the last parameter, is to set the encoding
Below we look at the code by the case of different, the result of what a huge difference
$str = ' We all have a dream rventrc ';
$str = Mb_substr ($str, 0,3); Since no encoding is specified, the 1 Chinese characters are 3 characters long and output: ' I '
$str = Mb_substr ($str, 0,3, ' UTF8 '); Because the UTF8 encoding is specified, a Chinese character is 1 characters long and therefore outputs: ' We all '
$str = Mb_substr ($str, -4,2, ' UTF8 '); This means starting from the bottom 4th , capturing 2-length characters
The expression starts at subscript 2 and is truncated to the 5th character (minus 5th), so the result is: ' There's a dream RV '
$str = Mb_substr ($str, 2, -5, ' UTF8 ');
Through tonight's detailed analysis, we have a clearer understanding of the interception of Chinese strings, in fact, the setup code is easy to solve,
If you feel that the article is helpful to yourself, be free to Play Rewards a little Oh!
The above describes the PHP string splitting function mb_substr, including the aspects of the content, I hope to be interested in PHP tutorial friends helpful.