php批量轉換文件夾下所有文件編碼的函數(shù)類
更新時間:2017年08月06日 17:39:23 投稿:mdxy-dxy
分享一個php轉換文件夾下所有文件編碼函數(shù)類,適合發(fā)布網(wǎng)站的其他編碼版本,比如你有一個GBK版本 你想有一個UTF8版本 或者你只有GBK的源碼 你想二次開發(fā) 但是你不想改變IDE的編碼方式 你可以用這個程序將其批量轉化為UTF8
函數(shù)代碼:
<?php /** * 把一個文件夾里的文件全部轉碼 只能轉一次 否則全部變亂碼 * @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函數(shù)不工作 { return; }*/ $contents_after = iconv($input_encoding,$output_encoding,$contents_before); file_put_contents($filename, $contents_after); } } else { echo '參數(shù)錯誤'; return false; } } iconv_file('./test'); ?>
注意:把一個文件夾里的文件全部轉碼 只能轉一次 否則全部變亂碼
相關文章
php版交通銀行網(wǎng)銀支付接口開發(fā)入門教程
這篇文章主要介紹了php版交通銀行網(wǎng)銀支付接口開發(fā)方法,結合簡單實例形式分析了php操作交通銀行網(wǎng)銀接口的的開發(fā)步驟與相關操作技巧,需要的朋友可以參考下2016-09-09