3v4l.org

run code in 300+ PHP versions simultaneously
<?php // EXAMPLE USAGE $array = generate(); echo $array[0]; echo "<br />"; echo $array[1]; // FUNCTION function 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(9, 9), 1); //random number $id .= substr($digilist, rand(21, 21), 1); //then a letter $id .= substr($digilist, rand(13, 13), 1); //another letter $id .= substr($digilist, rand(2, 9), 1); //a number $id .= substr($digilist, rand(6, 6), 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 7.0.7 - 7.0.8, 7.0.13, 7.0.17 - 7.0.18, 7.1.1, 7.1.10, 7.1.32, 7.2.14, 7.2.18, 7.2.21 - 7.2.23, 7.3.0, 7.3.5, 7.3.8, 7.4.0
9MD76<br />RDMX-7RTL-2HQ8-4HLT
Output for 7.0.5 - 7.0.6, 7.0.9, 7.1.7, 7.1.25, 7.1.31, 7.2.7, 7.3.10, 7.3.12
9MD96<br />028B-JV0B-8GKN-1FNX
Output for 7.1.0, 7.1.4, 7.2.2, 7.2.15, 7.2.20, 7.3.11
9MD36<br />FVHJ-8MQH-U6BY-PAED
Output for 7.0.2, 7.0.19, 7.2.1, 7.2.6, 7.2.13, 7.2.16 - 7.2.17, 7.2.24 - 7.2.25, 7.3.9
9MD26<br />H7A7-LVBU-2PAA-RJUF
Output for 7.0.11, 7.1.5, 7.1.27, 7.1.30, 7.1.33, 7.2.5, 7.3.7
9MD46<br />E7K2-9BUV-JVVY-YEVK
Output for 7.0.1, 7.0.4, 7.0.10, 7.0.15 - 7.0.16, 7.1.2, 7.1.6, 7.1.26, 7.1.28, 7.2.8, 7.2.10, 7.2.12, 7.3.1 - 7.3.3, 7.3.6
9MD66<br />6TYM-LN2X-HJ1W-HX2B
Output for 7.0.14, 7.0.20, 7.1.3, 7.2.0, 7.2.3, 7.2.9, 7.2.11, 7.3.4
9MD56<br />GQ5C-GTRU-6403-F3BA
Output for 7.0.0, 7.0.3, 7.0.12, 7.1.29, 7.2.4, 7.2.19
9MD86<br />LT2G-RWPQ-B3V3-Q4MQ

preferences:
106.08 ms | 402 KiB | 84 Q