Thursday, February 6, 2014

Convert special character to normal character in PHP

   
    > You need to convert special character to normal character. Below are the list of some special character:
   
    $special_chars = array(
        'À','à','Á','á','Â','â','Ã','ã','Ä','ä','Å','å','Ă','ă','Ą','ą',
        'Ć','ć','Č','č','Ç','ç',
        'Ď','ď','Đ','đ',
        'È','è','É','é','Ê','ê','Ë','ë','Ě','ě','Ę','ę',
        'Ğ','ğ',
        'Ì','ì','Í','í','Î','î','Ï','ï',
        'Ĺ','ĺ','Ľ','ľ','Ł','ł',
        'Ñ','ñ','Ň','ň','Ń','ń',
        'Ò','ò','Ó','ó','Ô','ô','Õ','õ','Ö','ö','Ø','ø','ő',
        'Ř','ř','Ŕ','ŕ',
        'Š','š','Ş','ş','Ś','ś',
        'Ť','ť','Ť','ť','Ţ','ţ',
        'Ù','ù','Ú','ú','Û','û','Ü','ü','Ů','ů',
        'Ÿ','ÿ','ý','Ý',
        'Ž','ž','Ź','ź','Ż','ż');
       
         Now try the below code to convert these to normal character :
       
        $text = "éèçâñüÄ";
        $htmlchar = htmlentities($text, ENT_COMPAT, 'UTF-8');  //éèçâñüÄ
        $text = preg_replace("/&([a-z])[a-z]+;/i", "$1", htmlentities($text, ENT_COMPAT, 'UTF-8'));  //eecanuA