: This article mainly introduces the extraction of php strings. if you are interested in the PHP Tutorial, you can refer to it. I. INTRODUCTION
Today we will introduce mb_substr () and mb_cutstr (). Php programming, whether it is web websites or platform development, uses string truncation in many cases. Before using php, modify the php. ini configuration file, open php_mbstring.dll, and remove the semicolon.
Php_mbstring.dll is a string encoding and string processing library. It is used to process unicode-based strings, such as UTF-8 and Chinese characters.
II. demonstration
1.
$ Str = 'nothing, that is why we fight! '; Echo mb_substr ($ str, 0,7, 'utf-8 ');
The output result is: nothing.
The mb_substr function has three parameters: the first is the string, the second is the starting and ending position of the truncation, and the third is the string encoding. it is very effective to intercept Chinese characters and prevent garbled characters. It is split by the number of words.
2.
$ Str = 'nothing, that is why we fight! '; Echo mb_strcut ($ str, 0,7, 'utf-8 ');
Output result: None
The mb_strcut function also has three parameters: character, start and end positions, and character encoding. Different from mb_substr, it is divided by the number of bytes. A word contains two bytes, but it does not contain half or half a byte. when the remaining one byte is used, no more words will be output.
III. Summary
Most of these two functions are used, and there is also a substr function, which is also used to extract strings, but it will encounter garbled characters when it is extracted, and is suitable for English. While mb_substr and mb_strcut are eaten by chinetouch. If you are interested, try this function on your own.
The above introduces the extraction of php strings, including the content, and hope to be helpful to friends who are interested in PHP tutorials.