3v4l.org

run code in 300+ PHP versions simultaneously
<?php// EXAMPLE USAGE$array = generate();echo $array[0];echo "<br />";echo $array[1];// FUNCTIONfunction generate(){ $digilist = "0123456789ABCDEFGHJKLMNPQRTUVWXY"; //now we generate a new random ID number using the substrings of the digitList string above $id = NULL; $id .= substr($digilist, rand(1, 9), 1); //random number $id .= substr($digilist, rand(10, 31), 1); //then a letter $id .= substr($digilist, rand(10, 31), 1); //another letter $id .= substr($digilist, rand(1, 9), 1); //a number $id .= substr($digilist, rand(1, 9), 1); //and finally another number - simple :D //ok so now we need to generate an MD5 hash of our ID $hash = md5($id); //cycle through the hash 16 (length of key) times (in steps of 2 because each hex bytes is 2 digits long) $i = 0; $key = NULL; for ($i; $i < 32; $i+=2) { //here we convert the next hex value to an integer and perform a bitwise AND operation against '31' //31 is the highest substring value in our digit list. $nextdigit = hexdec(substr($hash, $i, 2)) & 31; //if 'i' is divisable by 8 (every 4 cycles) then we want to add "-" if ((($i % 8) == 0) && ($i > 0)) { $key .= "-".substr($digilist, $nextdigit, 1); } else { $key .= substr($digilist, $nextdigit, 1); } } $array = array($id, $key); //return return $array;}?>
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 7.2.29 - 7.2.33, 7.3.16 - 7.3.31, 7.4.0 - 7.4.32, 8.0.0 - 8.0.12, 8.0.14 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
<?php// EXAMPLE USAGE$array = generate();echo $array[0];echo "<br />";echo $array[1];// FUNCTIONfunction generate(){ $digilist = "0123456789ABCDEFGHJKLMNPQRTUVWXY"; //now we generate a new random ID number using the substrings of the digitList string above $id = NULL; $id .= substr($digilist, rand(1, 9), 1); //random number $id .= substr($digilist, rand(10, 31), 1); //then a letter $id .= substr($digilist, rand(10, 31), 1); //another letter $id .= substr($digilist, rand(1, 9), 1); //a number $id .= substr($digilist, rand(1, 9), 1); //and finally another number - simple :D //ok so now we need to generate an MD5 hash of our ID $hash = md5($id); //cycle through the hash 16 (length of key) times (in steps of 2 because each hex bytes is 2 digits long) $i = 0; $key = NULL; for ($i; $i < 32; $i+=2) { //here we convert the next hex value to an integer and perform a bitwise AND operation against '31' //31 is the highest substring value in our digit list. $nextdigit = hexdec(substr($hash, $i, 2)) & 31; //if 'i' is divisable by 8 (every 4 cycles) then we want to add "-" if ((($i % 8) == 0) && ($i > 0)) { $key .= "-".substr($digilist, $nextdigit, 1); } else { $key .= substr($digilist, $nextdigit, 1); } } $array = array($id, $key); //return return $array;}?>
Output for 8.0.13
Fatal error: Uncaught Error: Undefined constant "php" in /in/NTK79:1 Stack trace: #0 {main} thrown in /in/NTK79 on line 1
Process exited with code 255.
Output for 7.2.0 - 7.2.13, 7.3.0, 7.3.32 - 7.3.33, 7.4.33
Warning: Use of undefined constant php - assumed 'php' (this will throw an Error in a future version of PHP) in /in/NTK79 on line 1
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.38, 7.0.0 - 7.0.33, 7.1.0 - 7.1.25
Notice: Use of undefined constant php - assumed 'php' in /in/NTK79 on line 1

preferences:
322.56 ms | 403 KiB | 422 Q