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

What to do if php rename Chinese garbled characters

藏色散人
藏色散人Original
2021-05-19 09:08:413025browse

php rename Chinese garbled solution: first open the corresponding PHP code file; then change GB2312 to GBK through the "iconv("GBK","UTF-8",$a);" method .

What to do if php rename Chinese garbled characters

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

php windows rename Chinese error

The rename() function can rename files, directories, etc., but pay attention to the encoding of the destination and starting address.

For example: My PHP file encoding is UTF-8, but the default Chinese encoding in the WINDOW system is GBK, so I should write like this:

rename(iconv('UTF-8','GBK',$dir.$filename), iconv('UTF-8','GBK',$dir.$newFileName));

OK, Perfect

When using the iconv function to convert Chinese character strings in php, the following error is prompted:

Notice: iconv() [function.iconv]: Detected an illegal character in input string in a.php on line 796

The error statement is as follows:

iconv("GB2312","UTF-8",$a);

The solution is to change GB2312 to GBK:

iconv("GBK","UTF-8",$a);

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What to do if php rename 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