溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

使用php怎么批量轉(zhuǎn)換文件夾的編碼

發(fā)布時間:2021-02-24 15:38:20 來源:億速云 閱讀:143 作者:戴恩恩 欄目:開發(fā)技術(shù)

這篇文章主要介紹了使用php怎么批量轉(zhuǎn)換文件夾的編碼,億速云小編覺得不錯,現(xiàn)在分享給大家,也給大家做個參考,一起跟隨億速云小編來看看吧!

php有什么用

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)站推薦給身邊好友。

向AI問一下細節(jié)

免責聲明:本站發(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)容。

php
AI