fixEncoding in PHP

By: mrezair Viewed: 1379 times  Printer Friendly Format    

I found this little function very useful in fixing strings that are not in utf-8 but need be converted .

// Fixes the encoding to uf8 
function fixEncoding($in_str) 
  $cur_encoding = mb_detect_encoding($in_str) ; 
  if($cur_encoding == "UTF-8" && mb_check_encoding($in_str,"UTF-8")) 
    return $in_str; 
    return utf8_encode($in_str); 
} // fixEncoding 

Most Viewed Articles (in PHP )

Latest Articles (in PHP)

Comment on this tutorial