There are many ways to process strings in PHP. Tonight we have selected a very representative and widely used function to explain. It is the character
characterstring splitting function: mb_substr( ), I hope everyone will recognizetrue learning and understand!
// mb_substr() has several parameters, usually 3 or 4 parameters. Let’s talk about the last parameter in particular, which is to set the encoding
// Let’s look at the different encodings through cases below , what is the huge difference in the result
$str = 'We all have a dream rventrc'; $str = mb_substr($str, 0,3); // Since no encoding is specified,
1 Chinese character is treated as 3 characters in length, it will output: '我' $str = mb_substr($str, 0,3,'utf8'); // Since
utf8 encoding is specified, one Chinese character is 1 character in length, so it will be output :'We all' $str = mb_substr($str, -4,2,'utf8'); // This means starting from the 4th
from the bottom of , intercepting 2 characters of length // It means starting from the subscript Starting from 2, intercept until the 5th character from the bottom (excluding the 5th from the bottom)
, so the result is: 'Everyone has a dream rv'
Through tonight’s detailed analysis, I believe everyone has a clearer understanding of intercepting Chinese strings. In fact, it can be easily solved by setting the encoding,
If you think the article is helpful to you, you can feel free to
tip a little!
The above introduces the PHP string splitting function mb_substr, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.