3v4l.org

run code in 300+ PHP versions simultaneously
<?php //Source: https://bugs.php.net/bug.php?id=63898 /* $key = utf8_encode("Foo " . chr(163)); $array = array($key => ""); var_dump($array); $json = json_encode($array); var_dump($json); $array2 = array($key); var_dump($array2, json_encode($array2)); var_dump(json_encode(utf8_encode('hey now ' . chr(180) . ' you’re dumb'))); var_dump(json_encode('hey now ' . chr(180) . ' you’re dumb')); */ $text = 'hey ' . chr(160); $arr = array('damnit' => $text); $utf = utf8_encode($text); $utfarr = array('damnit' => $utf); $json = json_encode($arr,JSON_UNESCAPED_UNICODE); $utfjson = json_encode($utfarr,JSON_UNESCAPED_UNICODE); var_dump($json, $utfjson); var_dump(json_decode($json), json_decode($utfjson)); /* $x = 'Audio Pass: Get live NFL game audio while you’re on the road with Audio Pass.'; var_dump(htmlentities($x)); var_dump(htmlentities($x, ENT_COMPAT | ENT_SUBSTITUTE, 'ISO-8859-1')); var_dump(htmlentities($x, ENT_COMPAT | ENT_SUBSTITUTE, 'UTF-8')); */
Output for 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Deprecated: Function utf8_encode() is deprecated in /in/4fGpv on line 22 bool(false) string(19) "{"damnit":"hey  "}" NULL object(stdClass)#1 (1) { ["damnit"]=> string(6) "hey  " }
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28
bool(false) string(19) "{"damnit":"hey  "}" NULL object(stdClass)#1 (1) { ["damnit"]=> string(6) "hey  " }
Output for 5.4.0 - 5.4.45
string(15) "{"damnit":null}" string(19) "{"damnit":"hey  "}" object(stdClass)#1 (1) { ["damnit"]=> NULL } object(stdClass)#2 (1) { ["damnit"]=> string(6) "hey  " }
Output for 5.3.0 - 5.3.29
Notice: Use of undefined constant JSON_UNESCAPED_UNICODE - assumed 'JSON_UNESCAPED_UNICODE' in /in/4fGpv on line 24 Warning: json_encode() expects parameter 2 to be long, string given in /in/4fGpv on line 24 Notice: Use of undefined constant JSON_UNESCAPED_UNICODE - assumed 'JSON_UNESCAPED_UNICODE' in /in/4fGpv on line 25 Warning: json_encode() expects parameter 2 to be long, string given in /in/4fGpv on line 25 NULL NULL NULL NULL
Output for 5.2.0 - 5.2.17
Notice: Use of undefined constant JSON_UNESCAPED_UNICODE - assumed 'JSON_UNESCAPED_UNICODE' in /in/4fGpv on line 24 Warning: json_encode() expects exactly 1 parameter, 2 given in /in/4fGpv on line 24 Notice: Use of undefined constant JSON_UNESCAPED_UNICODE - assumed 'JSON_UNESCAPED_UNICODE' in /in/4fGpv on line 25 Warning: json_encode() expects exactly 1 parameter, 2 given in /in/4fGpv on line 25 NULL NULL NULL NULL
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6
Fatal error: Call to undefined function json_encode() in /in/4fGpv on line 24
Process exited with code 255.
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: json_encode() in /in/4fGpv on line 24
Process exited with code 255.
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.4
Fatal error: Call to undefined function: json_encode() in /in/4fGpv on line 24
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: json_encode() in /in/4fGpv on line 24

preferences:
268.85 ms | 401 KiB | 397 Q