: This article mainly introduces the PHP string splitting function mb_substr. if you are interested in the PHP Tutorial, refer to it. PHP has many methods to process strings. tonight we have selected a very representative and widely used function explanation. it is a word.
String sharding function: mb_substr (). I hope you can learn it carefully!
// Mb_substr () has several parameters, usually three or four. in particular, the last parameter is encoded.
// In the following example, we will show how different codes are produced.
$ Str = 'We all have a dream rventrc ';
$ Str = mb_substr ($ str,); // because no encoding is specified, when one Chinese character is 3 characters long, it will output: 'me'
$ Str = mb_substr ($ str, 'utf8'); // because utf8 encoding is specified, a Chinese character must be 1 character in length, so the output will be:''
$ Str = mb_substr ($ str,-4th, 'utf8'); // This indicates that two characters are truncated starting from the last characters.
// It indicates that starting from subscript 2, it is intercepted until the last 5th characters (excluding the last 5th characters). Therefore, the result is: 'All have a dream RVs'
$ Str = mb_substr ($ str, 2,-5, 'utf8 ');
Through detailed analysis tonight, we believe we have a clearer understanding of intercepting Chinese strings. In fact, it is easy to set up encoding,
If you think the article is helpful to you, you can enjoy it at will!
The above introduces the PHP string sharding function mb_substr, including some content, hope to be helpful to friends who are interested in the PHP Tutorial.