Cyrillic characters in PHP's json_encode

Can't you use JSON_UNESCAPED_UNICODE constant here?


I found this in the code of Zend framework:

http://framework.zend.com/svn/framework/standard/trunk/library/Zend/Json/Decoder.php

Take a look at the function decodeUnicodeString ( line 474 ):

 /**
     * Decode Unicode Characters from \u0000 ASCII syntax.
     *
     * This algorithm was originally developed for the
     * Solar Framework by Paul M. Jones
     *
     * @link   http://solarphp.com/
     * @link   http://svn.solarphp.com/core/trunk/Solar/Json.php
     * @param  string $value
     * @return string
     */
    public static function decodeUnicodeString($chrs)

It's static, and you can easily extract it - just replace the line:

490:           $utf8 .= self::_utf162utf8($utf16);

with:

490:           $utf8 .= mb_convert_encoding($utf16, 'UTF-8', 'UTF-16');

Not an ideal solution, but did the job for me :o)


$str = json_encode($arr, JSON_UNESCAPED_UNICODE);

The use of this solution worked for me with the Latin and the Cyrillic alphabet, with PHP 5.5

Tags:

Php

Json

Utf 8