#The substr in PHP is garbled in Chinese?
The substr Chinese characters in PHP are garbled. The reason is that the "substr" function splits Chinese characters according to the length of 3, so it will cause garbled characters. The solution is to use the function in the "mbstring" extension. "mb_substr", this function will calculate a Chinese character as length 1.
Usage examples
"; echo substr($str,0,12)."
"; echo mb_strlen($str,"UTF8")."
"; echo mb_substr($str,0,12,"UTF8")."
"; ?>
Recommended tutorial: "PHP"
The above is the detailed content of Chinese substr in PHP is garbled?. For more information, please follow other related articles on the PHP Chinese website!