Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

json_encode with option JSON_UNESCAPED_UNICODE [closed]

Tags:

json

php

When using echo json_encode($array, JSON_UNESCAPED_UNICODE);

I get the this error

Warning: json_encode() expects exactly 1 parameter, 2 given

like image 313
Ben Avatar asked Mar 21 '12 09:03

Ben


2 Answers

Your php version might be too low:

http://php.net/manual/en/function.json-encode.php

string json_encode ( mixed $value [, int $options = 0 ] )

5.3.0    The options parameter was added
like image 84
biziclop Avatar answered Nov 07 '22 21:11

biziclop


See patch at http://code.google.com/p/apns-php/issues/detail?id=22 which allows the same functionality on PHP 5.2.

Basically run something like this:

foreach ($array as &$val) {
    $val = preg_replace_callback('/\\\\u([0-9a-f]{4})/i',
        function($matches) {
            return mb_convert_encoding(pack('H*', $matches[1]), 'UTF-8', 'UTF-16');
        }, $val);
}
like image 4
pevik Avatar answered Nov 07 '22 21:11

pevik