php文件夹转换网页,PHP转换文件夹下所有文件的编码 适合发布网站的其他编码版本...
PHP轉換文件夾下所有文件的編碼 適合發布網站的其他編碼版本 比如你有一個GBK版本 你想有一個UTF8版本 或者你只有GBK的源碼 你想二次開發 但是你不想改變IDE的編碼方式 你可以用這個程序將其批量轉化為UTF8.
/**
* 把一個文件夾里的文件全部轉碼 只能轉一次 否則全部變亂碼
* @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函數不工作
{
return;
}*/
$contents_after = iconv($input_encoding,$output_encoding,$contents_before);
file_put_contents($filename, $contents_after);
}
}
else
{
echo '參數錯誤';
return false;
}
}
iconv_file('./test');
?>
總結
以上是生活随笔為你收集整理的php文件夹转换网页,PHP转换文件夹下所有文件的编码 适合发布网站的其他编码版本...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python nonetype报错_py
- 下一篇: python怎么输入一个数字并调用_Py