3v4l.org

run code in 300+ PHP versions simultaneously
<?php // taken from walf, http://www.php.net/manual/en/function.hex2bin.php // this function comes with PHP >= 5.4.0 if (!function_exists('hex2bin')) { function hex2bin($data) { static $old; if ($old === null) { $old = version_compare(PHP_VERSION, '5.2', '<'); } $isobj = false; if (is_scalar($data) || (($isobj = is_object($data)) && method_exists($data, '__toString'))) { if ($isobj && $old) { ob_start(); echo $data; $data = ob_get_clean(); } else { $data = (string) $data; } } else { trigger_error(__FUNCTION__.'() expects parameter 1 to be string, ' . gettype($data) . ' given', E_USER_WARNING); return; //null in this case } $len = strlen($data); if ($len % 2) { trigger_error(__FUNCTION__.'(): Hexadecimal input string must have an even length', E_USER_WARNING); return false; } if (strspn($data, '0123456789abcdefABCDEF') != $len) { trigger_error(__FUNCTION__.'(): Input string must be hexadecimal string', E_USER_WARNING); return false; } return pack('H*', $data); } } function heutf8($str, $ent_constant = ENT_COMPAT) { return htmlentities($str, $ent_constant, 'UTF-8'); } $str = hex2bin('c0206c61206d6169736f6e'); print(heutf8($str)); ?>
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.30, 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, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6

preferences:
218.49 ms | 405 KiB | 346 Q