3v4l.org

run code in 300+ PHP versions simultaneously
<?php if (!defined('PHP_EOL')) { define('PHP_EOL', "\r\n"); } // generate the 32bit byte array (if you have the "openssl_random_pseudo_bytes" function available) if (function_exists('openssl_random_pseudo_bytes')) { $random_key = openssl_random_pseudo_bytes(32); } else { // this is the longer way to do it... $random_key = ''; for( $i = 0; $i < 64; $i++) { $random_key .= ((bool)rand(0, 1) ? chr(rand(65, 90)) : rand(0, 9)); } $random_key = hex2dec($random_key); } // this is it as hex print "Hex key: " . bin2hex($random_key) . PHP_EOL; print PHP_EOL; // this is the base64 string that you want to save print "Save this string: " . base64_encode($random_key) . PHP_EOL;
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.25, 7.3.0 - 7.3.12, 7.4.0
Fatal error: Uncaught Error: Call to undefined function hex2dec() in /in/rZOTf:16 Stack trace: #0 {main} thrown in /in/rZOTf on line 16
Process exited with code 255.
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.38
Fatal error: Call to undefined function hex2dec() in /in/rZOTf on line 16
Process exited with code 255.
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: hex2dec() in /in/rZOTf on line 16
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: hex2dec() in /in/rZOTf on line 16
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: hex2dec() in /in/rZOTf on line 16

preferences:
213.83 ms | 401 KiB | 317 Q