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);
Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.27, 8.4.1 - 8.4.14
bin2hex: \x62\x61\x73\x65\x36\x34\x5f\x64\x65\x63\x6f\x64\x65 unpack: \x62\x61\x73\x65\x36\x34\x5f\x64\x65\x63\x6f\x64\x65 sprintf: \x62\x61\x73\x65\x36\x34\x5F\x64\x65\x63\x6F\x64\x65 ------------------------- decoded: hex2bin: base64_decode pack: base64_decode sscanf + vprintf base64_decode

preferences:
107.3 ms | 407 KiB | 5 Q