Home > Backend Development > PHP Problem > How to change the PHP configuration file php.ini to solve garbled characters?

How to change the PHP configuration file php.ini to solve garbled characters?

coldplay.xixi
Release: 2023-03-02 10:22:02
Original
3448 people have browsed it

How to change the PHP configuration file php.ini to solve the garbled code: first open the PHP configuration file [php.ini]; then remove the semicolon before [;extension=php_mbstring.dll]; finally restart Apache. Can.

How to change the PHP configuration file php.ini to solve garbled characters?

How to change the PHP configuration file php.ini to solve the garbled code:

php uses XmlHttp and uses Utf by default -8 character set, and we mostly use the GB2312 character set, which requires us to transcode from GB2312 to Utf-8.
PHP provides an optional special code module that can realize mutual conversion between multiple character sets. The method to load this special code module is as follows:

  • Open the PHP configuration file php.ini and add ;extension=php_mbstring.dll (linux is php_mbstring.so) Remove the semicolon.

  • After restarting Apache, this module can be used.

  • If an error occurs, please check whether the path setting of the extension directory is correct.
    After loading this module, we can use the mb_convert_encoding function to transcode:

<?      
$utf8_string = mb_convert_encoding($gb_string, ’UTF-8’, ’GB2312’);      
?>
Copy after login


Convert the transcoded characters After the output, you can see the correctly displayed Chinese

echo and you will see it.

Related learning recommendations: PHP programming from entry to proficiency

The above is the detailed content of How to change the PHP configuration file php.ini to solve garbled characters?. 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