Ejemplo n.º 1
0
 private static function dec2char($n)
 {
     // converts a single string representing a decimal number to a character
     // note that no checking is performed to ensure that this is just a hex number, eg. no spaces etc
     // dec: string, the dec codepoint to be converted
     $result = '';
     if ($n <= 0xffff) {
         $result .= Z_Unicode::fromCharCode($n);
     } else {
         if ($n <= 0x10ffff) {
             $n -= 0x10000;
             $result .= Z_Unicode::fromCharCode(0xd800 | $n >> 10) . Z_Unicode::fromCharCode(0xdc00 | $n & 0x3ff);
         } else {
             throw new Exception('dec2char error: Code point out of range: ' . dechex($n));
         }
     }
     return $result;
 }
Ejemplo n.º 2
0
 public static function encodeRelativeDescriptorString($str)
 {
     if (function_exists('normalizer_normalize')) {
         $str = normalizer_normalize($str);
     }
     $str = Z_Unicode::convertCharStr2UTF8($str);
     // convertNumbers2Char($str, 'hex')
     $str = preg_replace_callback("/([A-Fa-f0-9]{2})/", function ($matches) {
         return Z_Unicode::hex2char($matches[0]);
     }, str_replace(" ", "", $str));
     return $str;
 }
Ejemplo n.º 3
0
 private static function utf8_decode($utftext)
 {
     $string = "";
     $i = 0;
     $c = $c1 = $c2 = 0;
     while ($i < mb_strlen($utftext)) {
         $c = Z_Unicode::charCodeAt($utftext, $i);
         if ($c < 128) {
             $string .= Z_Unicode::fromCharCode($c);
             $i++;
         } else {
             if ($c > 191 && $c < 224) {
                 $c2 = Z_Unicode::charCodeAt($utftext, $i + 1);
                 $string .= Z_Unicode::fromCharCode(($c & 31) << 6 | $c2 & 63);
                 $i += 2;
             } else {
                 $c2 = Z_Unicode::charCodeAt($utftext, $i + 1);
                 $c3 = Z_Unicode::charCodeAt($utftext, $i + 2);
                 $string .= Z_Unicode::fromCharCode(($c & 15) << 12 | ($c2 & 63) << 6 | $c3 & 63);
                 $i += 3;
             }
         }
     }
     return $string;
 }