Chinese substr in PHP is garbled?

Guanhui
Release: 2023-03-02 22:02:02
Original
2958 people have browsed it

Chinese substr in PHP is garbled?

#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")."
"; ?>
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!