3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $source = "this is a test"; $escaped = implode("", array_map(function($char) { if (ctype_alnum($char)) { return $char; } $bytelen = mb_strlen($char, '8bit'); $result = '\\u'; for ($i = 0; $i < $bytelen; $i++) { $result .= str_pad(dechex(ord($char[$i])), 2, '0', STR_PAD_LEFT); } return $result; }, str_split($source, 1))); var_dump($escaped);
based on iZ35F
Output for 5.3.0 - 7.3.0rc4
string(23) "this\u20is\u20a\u20test"
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION, expecting ')' in /in/5V3U2 on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_FUNCTION, expecting ')' in /in/5V3U2 on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `')'' in /in/5V3U2 on line 5
Process exited with code 255.