首頁  >  文章  >  後端開發  >  php如何轉碼文件碼

php如何轉碼文件碼

王林
王林原創
2020-07-21 16:06:502975瀏覽

php轉碼檔案的方法是:先使用mb_detect_encoding()函式判斷​​檔案所使用的編碼;然後再使用函式mb_convert_encoding()來為檔案轉碼即可。

php如何轉碼文件碼

相關函數介紹:

(推薦教學:php教學

mb_convert_encoding()函數轉換字符編碼。

mb_detect_encoding() 函式判斷字串所使用的編碼。

函數語法:

mb_convert_encoding($str,$encoding1,$encoding2);

程式碼實作:

function characet($data){
  if( !empty($data) ){   
    $fileType = mb_detect_encoding($data , array('UTF-8','GBK','LATIN1','BIG5')) ;  
    if( $fileType != 'UTF-8'){  
      $data = mb_convert_encoding($data ,'utf-8' , $fileType);  
    }  
  }  
  return $data;   
}

以上是php如何轉碼文件碼的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn