The encoding of all files in the PHP transformation folder is suitable for publishing other coded versions of the site like you have a GBK version you want to have a UTF8 version or you only have GBK source code you want to develop two times but you don't want to change the IDE's encoding you can use this program to convert it to UTF8 in bulk:
The code is as follows:
Copy Code code as follows:
<?php
/**
* All the files in a folder can be transferred only once or all of them become 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 ');
?>