3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $json_data = array ('id'=>1,'name'=>"фыфыывфы",'country'=>'Russia'); function json_encode_cyr($str) { $arr_replace_utf = array('\u0410', '\u0430','\u0411','\u0431','\u0412','\u0432', '\u0413','\u0433','\u0414','\u0434','\u0415','\u0435','\u0401','\u0451','\u0416', '\u0436','\u0417','\u0437','\u0418','\u0438','\u0419','\u0439','\u041a','\u043a', '\u041b','\u043b','\u041c','\u043c','\u041d','\u043d','\u041e','\u043e','\u041f', '\u043f','\u0420','\u0440','\u0421','\u0441','\u0422','\u0442','\u0423','\u0443', '\u0424','\u0444','\u0425','\u0445','\u0426','\u0446','\u0427','\u0447','\u0428', '\u0448','\u0429','\u0449','\u042a','\u044a','\u042b','\u044b','\u042c','\u044c', '\u042d','\u044d','\u042e','\u044e','\u042f','\u044f'); $arr_replace_cyr = array('А', 'а', 'Б', 'б', 'В', 'в', 'Г', 'г', 'Д', 'д', 'Е', 'е', 'Ё', 'ё', 'Ж','ж','З','з','И','и','Й','й','К','к','Л','л','М','м','Н','н','О','о', 'П','п','Р','р','С','с','Т','т','У','у','Ф','ф','Х','х','Ц','ц','Ч','ч','Ш','ш', 'Щ','щ','Ъ','ъ','Ы','ы','Ь','ь','Э','э','Ю','ю','Я','я'); $str1 = json_encode($str); $str2 = str_replace($arr_replace_utf,$arr_replace_cyr,$str1); return $str2; } echo json_encode($json_data);?> <br /> <?php $json = json_encode_cyr($json_data); echo json_encode($json); ?><br /> <?php echo json_encode($json_data, JSON_UNESCAPED_UNICODE); ?>
Output for 5.4.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
{"id":1,"name":"\u0444\u044b\u0444\u044b\u044b\u0432\u0444\u044b","country":"Russia"}<br /> "{\"id\":1,\"name\":\"\u0444\u044b\u0444\u044b\u044b\u0432\u0444\u044b\",\"country\":\"Russia\"}"<br /> {"id":1,"name":"фыфыывфы","country":"Russia"}
Output for 5.3.0 - 5.3.29
{"id":1,"name":"\u0444\u044b\u0444\u044b\u044b\u0432\u0444\u044b","country":"Russia"}<br /> "{\"id\":1,\"name\":\"\u0444\u044b\u0444\u044b\u044b\u0432\u0444\u044b\",\"country\":\"Russia\"}"<br /> Notice: Use of undefined constant JSON_UNESCAPED_UNICODE - assumed 'JSON_UNESCAPED_UNICODE' in /in/G9f53 on line 45 Warning: json_encode() expects parameter 2 to be long, string given in /in/G9f53 on line 45
Output for 5.2.0 - 5.2.17
{"id":1,"name":"\u0444\u044b\u0444\u044b\u044b\u0432\u0444\u044b","country":"Russia"}<br /> "{\"id\":1,\"name\":\"\u0444\u044b\u0444\u044b\u044b\u0432\u0444\u044b\",\"country\":\"Russia\"}"<br /> Notice: Use of undefined constant JSON_UNESCAPED_UNICODE - assumed 'JSON_UNESCAPED_UNICODE' in /in/G9f53 on line 45 Warning: json_encode() expects exactly 1 parameter, 2 given in /in/G9f53 on line 45
Output for 5.0.0 - 5.1.6
Fatal error: Call to undefined function json_encode() in /in/G9f53 on line 39
Process exited with code 255.
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: json_encode() in /in/G9f53 on line 39
Process exited with code 255.
Output for 4.3.2 - 4.4.4
Fatal error: Call to undefined function: json_encode() in /in/G9f53 on line 39
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: json_encode() in /in/G9f53 on line 39