Home >Backend Development >PHP Problem >What to do if php explode Chinese garbled characters
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.
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!