SimplePie_Misc::windows_1252_to_utf8 PHP Method

windows_1252_to_utf8() public method

Converts a Windows-1252 encoded string to a UTF-8 encoded string
public windows_1252_to_utf8 ( string $string ) : string
$string string Windows-1252 encoded string
return string UTF-8 encoded string
    function windows_1252_to_utf8($string)
    {
        static $convert_table = array("�" => "€", "�" => "�", "�" => "‚", "�" => "ƒ", "�" => "„", "�" => "…", "�" => "†", "�" => "‡", "�" => "ˆ", "�" => "‰", "�" => "Š", "�" => "‹", "�" => "Œ", "�" => "�", "�" => "Ž", "�" => "�", "�" => "�", "�" => "‘", "�" => "’", "�" => "“", "�" => "”", "�" => "•", "�" => "–", "�" => "—", "�" => "˜", "�" => "™", "�" => "š", "�" => "›", "�" => "œ", "�" => "�", "�" => "ž", "�" => "Ÿ", "�" => " ", "�" => "¡", "�" => "¢", "�" => "£", "�" => "¤", "�" => "¥", "�" => "¦", "�" => "§", "�" => "¨", "�" => "©", "�" => "ª", "�" => "«", "�" => "¬", "�" => "­", "�" => "®", "�" => "¯", "�" => "°", "�" => "±", "�" => "²", "�" => "³", "�" => "´", "�" => "µ", "�" => "¶", "�" => "·", "�" => "¸", "�" => "¹", "�" => "º", "�" => "»", "�" => "¼", "�" => "½", "�" => "¾", "�" => "¿", "�" => "À", "�" => "Á", "�" => "Â", "�" => "Ã", "�" => "Ä", "�" => "Å", "�" => "Æ", "�" => "Ç", "�" => "È", "�" => "É", "�" => "Ê", "�" => "Ë", "�" => "Ì", "�" => "Í", "�" => "Î", "�" => "Ï", "�" => "Ð", "�" => "Ñ", "�" => "Ò", "�" => "Ó", "�" => "Ô", "�" => "Õ", "�" => "Ö", "�" => "×", "�" => "Ø", "�" => "Ù", "�" => "Ú", "�" => "Û", "�" => "Ü", "�" => "Ý", "�" => "Þ", "�" => "ß", "�" => "à", "�" => "á", "�" => "â", "�" => "ã", "�" => "ä", "�" => "å", "�" => "æ", "�" => "ç", "�" => "è", "�" => "é", "�" => "ê", "�" => "ë", "�" => "ì", "�" => "í", "�" => "î", "�" => "ï", "�" => "ð", "�" => "ñ", "�" => "ò", "�" => "ó", "�" => "ô", "�" => "õ", "�" => "ö", "�" => "÷", "�" => "ø", "�" => "ù", "�" => "ú", "�" => "û", "�" => "ü", "�" => "ý", "�" => "þ", "�" => "ÿ");
        return strtr($string, $convert_table);
    }

Usage Example

Example #1
0
 /**
  * Change a string from one encoding to another
  *
  * @param string $data Raw data in $input encoding
  * @param string $input Encoding of $data
  * @param string $output Encoding you want
  * @return string|boolean False if we can't convert it
  */
 public static function change_encoding($data, $input, $output)
 {
     $input = SimplePie_Misc::encoding($input);
     $output = SimplePie_Misc::encoding($output);
     // We fail to fail on non US-ASCII bytes
     if ($input === 'US-ASCII') {
         static $non_ascii_octects = '';
         if (!$non_ascii_octects) {
             for ($i = 0x80; $i <= 0xff; $i++) {
                 $non_ascii_octects .= chr($i);
             }
         }
         $data = substr($data, 0, strcspn($data, $non_ascii_octects));
     }
     // This is first, as behaviour of this is completely predictable
     if ($input === 'windows-1252' && $output === 'UTF-8') {
         return SimplePie_Misc::windows_1252_to_utf8($data);
     } elseif (function_exists('mb_convert_encoding') && ($return = SimplePie_Misc::change_encoding_mbstring($data, $input, $output))) {
         return $return;
     } elseif (function_exists('iconv') && ($return = SimplePie_Misc::change_encoding_iconv($data, $input, $output))) {
         return $return;
     } else {
         return false;
     }
 }
All Usage Examples Of SimplePie_Misc::windows_1252_to_utf8