3v4l.org

run code in 300+ PHP versions simultaneously
<?php $word = 'base64_decode'; echo 'bin2hex: ' . PHP_EOL; echo implode(array_map(function($char) { return '\x' . bin2hex($char); }, str_split($word))) . PHP_EOL . PHP_EOL; echo 'unpack: ' . PHP_EOL; echo implode(array_map(function($char) { return '\x' . implode(unpack('H*', $char)); }, str_split($word))) . PHP_EOL . PHP_EOL; echo 'sprintf: ' . PHP_EOL; echo $encoded = implode(array_map(function($char) { return sprintf('\x%02X', ord($char)); }, (array) str_split($word))); echo PHP_EOL . PHP_EOL; echo '-------------------------' . PHP_EOL . PHP_EOL . 'decoded:' . PHP_EOL; $hexadecimal = str_replace('\x', '', $encoded); echo 'hex2bin:' . PHP_EOL; echo hex2bin($hexadecimal) . PHP_EOL . PHP_EOL; echo 'pack:' . PHP_EOL; echo pack('H*', $hexadecimal) . PHP_EOL . PHP_EOL; echo 'sscanf + vprintf' . PHP_EOL; vprintf(str_repeat('%c', count($f = sscanf($hexadecimal, str_repeat('%02X', substr_count($encoded , '\x'))))), $f);

preferences:
27.4 ms | 418 KiB | 5 Q