PHP convert character encoding to UTF-8

a simply function that detect character code and covert to UTF-8

function convertUTF8($data) {
  if(!empty($data)) {    
    $encodeType = mb_detect_encoding($data , array('UTF-8','GBK','LATIN1','BIG5'));   
    if( $encodeType != 'UTF-8'){   
      $data = mb_convert_encoding($data ,'utf-8' , $encodeType);   
    }   
  }   
  return $data;    
}
This entry was posted in Development and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *