3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $a = array('<foo>',"'bar'",'"baz"','&blong&', "\xc3\xa9"); echo "Normal: ", json_encode($a), "\n"; echo "Tags: ", json_encode($a, JSON_HEX_TAG), "\n"; echo "Apos: ", json_encode($a, JSON_HEX_APOS), "\n"; echo "Quot: ", json_encode($a, JSON_HEX_QUOT), "\n"; echo "Amp: ", json_encode($a, JSON_HEX_AMP), "\n"; echo "Unicode: ", json_encode($a, JSON_UNESCAPED_UNICODE), "\n"; echo "All: ", json_encode($a, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE), "\n\n";
Output for 5.4.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Normal: ["<foo>","'bar'","\"baz\"","&blong&","\u00e9"] Tags: ["\u003Cfoo\u003E","'bar'","\"baz\"","&blong&","\u00e9"] Apos: ["<foo>","\u0027bar\u0027","\"baz\"","&blong&","\u00e9"] Quot: ["<foo>","'bar'","\u0022baz\u0022","&blong&","\u00e9"] Amp: ["<foo>","'bar'","\"baz\"","\u0026blong\u0026","\u00e9"] Unicode: ["<foo>","'bar'","\"baz\"","&blong&","é"] All: ["\u003Cfoo\u003E","\u0027bar\u0027","\u0022baz\u0022","\u0026blong\u0026","é"]
Output for 5.3.0 - 5.3.29
Normal: ["<foo>","'bar'","\"baz\"","&blong&","\u00e9"] Tags: ["\u003Cfoo\u003E","'bar'","\"baz\"","&blong&","\u00e9"] Apos: ["<foo>","\u0027bar\u0027","\"baz\"","&blong&","\u00e9"] Quot: ["<foo>","'bar'","\u0022baz\u0022","&blong&","\u00e9"] Amp: ["<foo>","'bar'","\"baz\"","\u0026blong\u0026","\u00e9"] Unicode: Notice: Use of undefined constant JSON_UNESCAPED_UNICODE - assumed 'JSON_UNESCAPED_UNICODE' in /in/60dqC on line 9 Warning: json_encode() expects parameter 2 to be long, string given in /in/60dqC on line 9 All: Notice: Use of undefined constant JSON_UNESCAPED_UNICODE - assumed 'JSON_UNESCAPED_UNICODE' in /in/60dqC on line 10 ["\u003Cfoo\u003E","\u0027bar\u0027","\u0022baz\u0022","\u0026blong\u0026","\u00e9"]
Output for 5.2.0 - 5.2.17
Normal: ["<foo>","'bar'","\"baz\"","&blong&","\u00e9"] Tags: Notice: Use of undefined constant JSON_HEX_TAG - assumed 'JSON_HEX_TAG' in /in/60dqC on line 5 Warning: json_encode() expects exactly 1 parameter, 2 given in /in/60dqC on line 5 Apos: Notice: Use of undefined constant JSON_HEX_APOS - assumed 'JSON_HEX_APOS' in /in/60dqC on line 6 Warning: json_encode() expects exactly 1 parameter, 2 given in /in/60dqC on line 6 Quot: Notice: Use of undefined constant JSON_HEX_QUOT - assumed 'JSON_HEX_QUOT' in /in/60dqC on line 7 Warning: json_encode() expects exactly 1 parameter, 2 given in /in/60dqC on line 7 Amp: Notice: Use of undefined constant JSON_HEX_AMP - assumed 'JSON_HEX_AMP' in /in/60dqC on line 8 Warning: json_encode() expects exactly 1 parameter, 2 given in /in/60dqC on line 8 Unicode: Notice: Use of undefined constant JSON_UNESCAPED_UNICODE - assumed 'JSON_UNESCAPED_UNICODE' in /in/60dqC on line 9 Warning: json_encode() expects exactly 1 parameter, 2 given in /in/60dqC on line 9 All: Notice: Use of undefined constant JSON_HEX_TAG - assumed 'JSON_HEX_TAG' in /in/60dqC on line 10 Notice: Use of undefined constant JSON_HEX_APOS - assumed 'JSON_HEX_APOS' in /in/60dqC on line 10 Notice: Use of undefined constant JSON_HEX_QUOT - assumed 'JSON_HEX_QUOT' in /in/60dqC on line 10 Notice: Use of undefined constant JSON_HEX_AMP - assumed 'JSON_HEX_AMP' in /in/60dqC on line 10 Notice: Use of undefined constant JSON_UNESCAPED_UNICODE - assumed 'JSON_UNESCAPED_UNICODE' in /in/60dqC on line 10 Warning: json_encode() expects exactly 1 parameter, 2 given in /in/60dqC on line 10
Output for 5.0.0 - 5.1.6
Normal: Fatal error: Call to undefined function json_encode() in /in/60dqC on line 4
Process exited with code 255.
Output for 4.4.5 - 4.4.9
Normal: Fatal error: Call to undefined function: json_encode() in /in/60dqC on line 4
Process exited with code 255.
Output for 4.3.2 - 4.4.4
Normal: Fatal error: Call to undefined function: json_encode() in /in/60dqC on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Normal: Fatal error: Call to undefined function: json_encode() in /in/60dqC on line 4