Home >Backend Development >PHP Problem >What to do if php explode Chinese garbled characters

What to do if php explode Chinese garbled characters

青灯夜游
青灯夜游Original
2021-05-26 18:01:392026browse

Solution: 1. In the php.ini configuration file, find and set the value of the "defalut_charset" item to "utf-8"; 2. In the php program, use "@ini_set(' default_charest','utf-8');" statement can set the encoding method.

What to do if php explode Chinese garbled characters

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

In PHP, use explode to split A Chinese string, for example, when using explode(':','fileName:filename'), the returned "filename" will be garbled. How to solve this? Let me introduce to you the solution below.

php explode Chinese garbled solution:

1. Configure the php.ini file

Settingsdefalut_charset = 'utf-8' ;

What encoding is used by the program? Just fill in the corresponding encoding here

2. Use ini_set()

If you cannot change php.ini, then You can use

@ini_set('default_charest','utf-8');

in a php program to achieve the same effect.

Description:

ini_set - Set the value for a configuration option. The syntax is as follows:

ini_set ( string $varname , string $newvalue )

Set the value of the specified configuration option. This option will retain its new value while the script is running, and will be restored when the script ends.

Parameters

  • varname: Not all valid options can be changed using ini_set(). There is an appendix with a list of valid options.

  • newvalue: The new value of the option.

Return value

  • Returns the old value on success, returns false on failure.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What to do if php explode Chinese garbled characters. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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