PHP truncation function mb_substr. In php, the mb_substr () function is a function used to intercept Chinese characters and English letters. it can be used to quickly intercept the length of specified characters. I will introduce it to you. Tip: In php, the mb_substr () function is used to intercept Chinese and English characters. it can be used to quickly and conveniently intercept the length of specified characters. I will introduce it to you.
Tip: mb_substr is not supported by default in php. we need to find php in the windows directory. ini open edit and search for mbstring. dll, find; extension = php_mbstring.dll and remove the previous; number to use the mb_substr function.
Function: mb_substr ($ str, $ start, $ length, $ encoding)
$ Str: string to be truncated
$ Start: truncation start
$ Length, length (note: This is different from mb_strimwidth. 1 represents a Chinese character)
$ Encoding, encoding, I set it to UTF-8
For example, the title of an article is truncated and 15 characters are allowed.
| The code is as follows: |
|
|
$ Str = 'so that my string will not contain garbled characters ^_^ ';
Echo "mb_substr:". mb_substr ($ str, 0, 7, 'utf-8 ');
// Result:
Echo"
";
Echo "mb_strcut:". mb_strcut ($ str, 0, 6, 'utf-8 ');
// Result:
?> |
In summary, he can intercept Chinese characters.
The extract () function is a function used to intercept Chinese and English characters. it can be used to quickly intercept specified characters. I will introduce it to you. Tip: mb_subs...