Home  >  Article  >  Backend Development  >  How to transcode files in php

How to transcode files in php

王林
王林Original
2020-07-21 16:06:503055browse

The method for php to transcode files is: first use the mb_detect_encoding() function to determine the encoding used by the file; then use the function mb_convert_encoding() to transcode the file.

How to transcode files in php

Related function introduction:

(Recommended tutorial: php tutorial)

mb_convert_encoding() Function converts character encoding.

mb_detect_encoding() function determines the encoding used by a string.

Function syntax:

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

Code implementation:

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;   
}

The above is the detailed content of How to transcode files in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn