First, introduce
Today is the introduction of MB_SUBSTR () and Mb_cutstr (). PHP programming, whether it is a Web site, or platform development, a lot of time to use the interception of strings. Before use, to modify the php.ini configuration file, the Php_mbstring.dll open, remove the front;
Php_mbstring.dll is a library of string encoding and string processing. is to handle Unicode-encoded strings, such as utf-8, Kanji, and so on.
Two, demo
1.
$str = ' Nothing is a reason to spell! '; Echo mb_substr ($str, 0,7, ' utf-8 ');
The output is: nothing, just
Mb_substr function has three parameters, the first is a string, the second is the location of the start and end of The Intercept, the third is the encoding of the string, interception of Chinese is very effective, to prevent garbled. It is segmented by the number of words.
2.
$str = ' Nothing is a reason to spell! '; Echo mb_strcut ($str, 0,7, ' utf-8 ');
The output is: no
Mb_strcut The function is also a three parameter, character, start and end position, character encoding. unlike mb_substr , it is divided by the number of bytes. A word of two bytes, and it does not appear half a word or half a byte of the case, when the remaining one byte will no longer output a word.
Three, Summary
most use these two functions, there is also a substr function, this function is also used to extract the string, but it is extracted when encountered in Chinese will be garbled error, suitable for use in English. and mb_substr and mb_strcut are both Chinese and English. You can also try this function on your own.
The above describes the PHP string extraction, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.