PHP converts the implementation code of all file codes in the folder. The encoding of all files in the PHP conversion folder is suitable for other encoding versions released on the website. for example, if you have a GBK version, you want to have a UTF8 version or you only have the GBK source code. if you want to develop a PHP conversion folder again the encoding of all files is suitable for other encoding versions released on the website. for example, if you have a GBK version, you want to have a UTF8 version or you only have the GBK source code. you want to perform further development, but you do not want to change the IDE encoding method. you can use this program to batch convert it to UTF8:
The code is as follows:
The code is as follows:
/**
* You can only transcode all files in a folder once. otherwise, all files are garbled.
* @ Param string $ filename
*/
Function iconv_file ($ filename, $ input_encoding = 'gbk', $ output_encoding = 'utf-8 ')
{
If (file_exists ($ filename ))
{
If (is_dir ($ filename ))
{
Foreach (glob ("$ filename/*") as $ key => $ value)
{
Iconv_file ($ value );
}
}
Else
{
$ Contents_before = file_get_contents ($ filename );
/* $ Encoding = mb_detect_encoding ($ contents_before, array ('cp936', 'ascii ', 'gbk', 'gb2312', 'utf-8 '));
Echo $ encoding;
If ($ encoding = 'utf-8') mb_detect_encoding function does not work
{
Return;
}*/
$ Contents_after = iconv ($ input_encoding, $ output_encoding, $ contents_before );
File_put_contents ($ filename, $ contents_after );
}
}
Else
{
Echo 'parameter error ';
Return false;
}
}
Iconv_file ('./test ');
?>
Others are suitable for publishing other website encoding versions. for example, if you have a GBK version, you want to have a UTF8 version, or if you only have the GBK source code, you want to develop it again...