What to do if php rename Chinese garbled characters

藏色散人
Release: 2023-03-09 18:52:01
Original
2965 people have browsed it

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));
Copy after login

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
Copy after login

The error statement is as follows:

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

The solution is to change GB2312 to GBK:

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

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!

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