String Mb_substr (string $str, int $start [, int $length = NULL [, String $encoding = Mb_internal_encoding ()]])-intercept string
(PHP 4 >= 4.0.6, PHP 5)
$str the target string to get the string from (the starting position of the string is 0)
$start, the position of the first character to be used in the $STR
$length, gets the length of the substring (note is not the end position)
$encoding, you can specify character encodings (typically used when working with Chinese characters, and this problem is very much)
<?phpmb_internal_encoding ("UTF-8"); If you change the UTF-8 to encode, the following values for the Chinese string processing will change. Echo mb_internal_encoding (). ""; Gets the character encoding for Iso-8859-1echo mb_substr (' Abcdefghijk ', 0,9). ""; Abcdefghiecho mb_substr (' Abcdefghijk ', 1,5). "; Bcdefecho Mb_substr (' We are all Chinese ', 0,9). ""; We are all Chinese echo mb_substr (' We are all Chinese ', 0,9, ' gb2312 '). We are all in echo mb_substr (' We are all Chinese ', 0,9, ' utf-8 '); We are all Chinese ?>
Summarize:
1, in the processing of English strings, the function of the fourth parameter ($encoding) can be ignored.
2, in the processing of Chinese strings, it is necessary to be careful, we must consider the coding problem, coding different, Chinese values are different.
3, when the Chinese string import database, it becomes more important.
4, the processing of string or text encoding ability, is a measure of the programmer's skill of a standard.