您好,登錄后才能下訂單哦!
這篇文章主要介紹了使用php怎么批量轉(zhuǎn)換文件夾的編碼,億速云小編覺得不錯,現(xiàn)在分享給大家,也給大家做個參考,一起跟隨億速云小編來看看吧!
php是一個嵌套的縮寫名稱,指的是英文超級文本預處理語言(php:Hypertext Preprocessor)的縮寫,它的語法混合了C、Java、Perl以及php自創(chuàng)新的語法,主要用來做網(wǎng)站開發(fā),許多小型網(wǎng)站都用php開發(fā),因為php是開源的,從而使得php經(jīng)久不衰。
函數(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'); ?>
以上就是億速云小編為大家收集整理的使用php怎么批量轉(zhuǎn)換文件夾的編碼,如何覺得億速云網(wǎng)站的內(nèi)容還不錯,歡迎將億速云網(wǎng)站推薦給身邊好友。
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。