Ejemplo n.º 1
0
 /**
  * @param string $value
  *
  * @return string
  */
 private function replaceUnicodeSequences($value)
 {
     return preg_replace_callback($this->patterns->getUnicodeEscapePattern(), function (array $match) {
         $code = $match[1];
         if (bin2hex($code) > 0xfffd) {
             $code = '\\FFFD';
         }
         return mb_convert_encoding(pack('H*', $code), 'UTF-8', 'UCS-2BE');
     }, $value);
 }
Ejemplo n.º 2
0
 /**
  * @param string $value
  *
  * @return string
  */
 private function replaceUnicodeSequences($value)
 {
     return preg_replace_callback($this->patterns->getUnicodeEscapePattern(), function ($match) {
         $c = hexdec($match[1]);
         if (0x80 > ($c %= 0x200000)) {
             return chr($c);
         }
         if (0x800 > $c) {
             return chr(0xc0 | $c >> 6) . chr(0x80 | $c & 0x3f);
         }
         if (0x10000 > $c) {
             return chr(0xe0 | $c >> 12) . chr(0x80 | $c >> 6 & 0x3f) . chr(0x80 | $c & 0x3f);
         }
     }, $value);
 }