Home > Article > Backend Development > What should I do if the name of the new php file is garbled?
Solution to the garbled name of a new php file: 1. Use the "iconv" or "mb_convert_encoding" function to convert the character encoding; 2. Use the "function convertEncoding($string){...}" method to implement the Just set the system settings to convert the encoding.
The operating environment of this tutorial: Windows 7 system, PHP version 8.1, Dell G3 computer.
php What should I do if the name of the new file is garbled?
Under Windows, when PHP calls the mkdir(), file_put_contents(), and fopen() functions to create a directory or document name with Chinese characters, garbled characters appear.
Cause
After consulting the information, this is related to the system character set.
windows (Simplified Chinese), the default character set is: gbk
windows (Traditional Chinese), the default character set is: big5
linux, the default character set is: utf-8
Solution
Use iconv or mb_convert_encoding function Convert character encoding.
//将字符串 str 从 in_charset 转换编码到 out_charset。 string iconv ( string $in_charset , string $out_charset , string $str ) //将 string 类型 str 的字符编码从可选的 from_encoding 转换到 to_encoding。 string mb_convert_encoding ( string $str , string $to_encoding [, mixed $from_encoding = mb_internal_encoding() ] )
Convert encoding according to system settings, the method is as follows:
Garbled code example
Solution example
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What should I do if the name of the new php file is garbled?. For more information, please follow other related articles on the PHP Chinese website!