Example #1
0
 public static function init()
 {
     self::$utf8validator = (bool) extension_loaded('utf8validator');
     mb_internal_encoding('UTF-8');
     mb_language('uni');
     mb_regex_encoding('UTF-8');
     mb_detect_order(array('UTF-8', 'ISO-8859-1'));
     mb_substitute_character(0xfffd);
     MCached::connect();
     $trans = MCached::get(self::TRANSKEY);
     if ($trans === MCached::NO_RESULT) {
         $win = "€" . implode('', range("‚", "Œ")) . "Ž" . implode('', range("‘", "œ")) . implode('', range("ž", "ÿ"));
         $win_iso = "�����";
         $iso = implode('', range("€", "ÿ"));
         $winlen = strlen($win);
         $winisolen = strlen($win_iso);
         $isolen = strlen($iso);
         $trans = array('iso_to_utf8' => array(), 'win_to_utf8' => array(), 'from_utf8' => array());
         for ($i = 0; $i < $isolen; $i++) {
             $utf8 = mb_convert_encoding($iso[$i], 'UTF-8', 'ISO-8859-1');
             $trans['iso_to_utf8'][$iso[$i]] = $utf8;
             $trans['from_utf8'][$utf8] = $iso[$i];
         }
         for ($i = 0; $i < $winlen; $i++) {
             $utf8 = mb_convert_encoding($win[$i], 'UTF-8', 'Windows-1252');
             $trans['win_to_utf8'][$win[$i]] = $utf8;
             $trans['from_utf8'][$utf8] = $win[$i];
         }
         for ($i = 0; $i < $winisolen; $i++) {
             $utf8 = mb_convert_encoding($win_iso[$i], 'UTF-8', 'ISO-8859-1');
             $trans['win_to_utf8'][$win_iso[$i]] = $utf8;
         }
         MCached::add(self::TRANSKEY, $trans, 86400);
     }
     self::$trans_table = $trans;
 }