How to solve garbled Chinese string interception with PHP

小云云
Release: 2023-03-22 10:00:01
Original
2148 people have browsed it

When using the substr() function to intercept Chinese strings, garbled characters often appear, because Chinese characters are generally three bytes or two bytes, etc., so we use the mb_substr() function to intercept Chinese characters. mb_substr() has good support for multi-byte characters and can be used in the same way as substr().

But to use the mb_substr() function, you must enable the mbstring extension. Find extension=mbstring in php.ini and remove the semicolon in front. This extension is not added by default.
Finally demonstrate this function:
How to solve garbled Chinese string interception with PHP
Use xdebug to check the value of the variable:
How to solve garbled Chinese string interception with PHP

It is often used when using the substr() function to intercept Chinese strings Garbled characters will appear because Chinese characters are generally three bytes or two bytes, etc., so we use the mb_substr() function to intercept Chinese characters. mb_substr() has good support for multi-byte characters and can be used in the same way as substr().
But to use the mb_substr() function, you must enable the mbstring extension. Find extension=mbstring in php.ini and remove the semicolon in front. This extension is not added by default.
Finally demonstrate this function:
How to solve garbled Chinese string interception with PHP
Use xdebug to check the value of the variable:
How to solve garbled Chinese string interception with PHP

Related recommendations:

php substr() function intercepts garbled Chinese strings_PHP tutorial

Solution to the problem of PHP intercepting garbled Chinese strings

php substr() function Intercept Chinese string garbled characters

The above is the detailed content of How to solve garbled Chinese string interception with PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
Popular Tutorials
More>
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!