函數(shù)代碼:
<?php /** * 把一個文件夾里的文件全部轉(zhuǎn)碼 只能轉(zhuǎn)一次 否則全部變亂碼 * @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'); ?>
注意:把一個文件夾里的文件全部轉(zhuǎn)碼 只能轉(zhuǎn)一次 否則全部變亂碼
【網(wǎng)站聲明】本站除付費源碼經(jīng)過測試外,其他素材未做測試,不保證完整性,網(wǎng)站上部分源碼僅限學習交流,請勿用于商業(yè)用途。如損害你的權(quán)益請聯(lián)系客服QQ:2655101040 給予處理,謝謝支持。