fixEncoding in PHP

By: mrezair  

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

<?php 
// 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; 
  else 
    return utf8_encode($in_str); 
} // fixEncoding 
?>




Archived Comments


Most Viewed Articles (in PHP )

File Handling in PHP

.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable

Using Sessions in PHP

preg_replace() and preg_replace_callback() in PHP

Encrypting and decrypting in PHP

PHP pages does not display in IIS 6 with Windows 2003

Installing PHP 5.x with Apache 2.x on HP UX 11i and configuring PHP 5.x with Oracle 9i

Cannot load /usr/local/apache/libexec/libphp4.so into server: ld.so.1:......

Setting up PHP in Windows 2003 Server IIS7, and WinXP 64

error: "Service Unavailable" after installing PHP to a Windows XP x64 Pro

Running different websites on different versions of PHP in Windows 2003 & IIS6 platform

Installing PHP with nginx-server under windows

Function to return number of digits of an integer in PHP

Function to force strict boolean values in PHP

Function to sort array by elements and count of element in PHP

Latest Articles (in PHP)