wat - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of wat.php

  1. <?php
  2. // EXAMPLE USAGE
  3.  
  4. $keys = 50;
  5.  
  6. for ($x = 0; $x <= $keys; $x++)
  7. {
  8.     $array = generate();
  9.     echo $array[0] . "<br>";
  10.     echo $array[1] . "<br><br>";
  11. }
  12.  
  13. // FUNCTION
  14. function generate()
  15. {
  16.         $digilist = "0123456789ABCDEFGHJKLMNPQRTUVWXY";
  17.  
  18.         //now we generate a new random ID number using the substrings of the digitList string above
  19.         $id = NULL;
  20.         $id .= substr($digilist, rand(1, 9), 1); //random number
  21.         $id .= substr($digilist, rand(10, 31), 1); //then a letter
  22.         $id .= substr($digilist, rand(10, 31), 1); //another letter
  23.         $id .= substr($digilist, rand(1, 9), 1); //a number
  24.         $id .= substr($digilist, rand(1, 9), 1); //and finally another number - simple :D
  25.                        
  26.     //ok so now we need to generate an MD5 hash of our ID
  27.         $hash = md5($id);
  28.  
  29.         //cycle through the hash 16 (length of key) times (in steps of 2 because each hex bytes is 2 digits long)
  30.         $i = 0;
  31.         $key = NULL;
  32.         for ($i; $i < 32; $i+=2)
  33.         {
  34.                 //here we convert the next hex value to an integer and perform a bitwise AND operation against '31'
  35.                 //31 is the highest substring value in our digit list.  
  36.                 $nextdigit = hexdec(substr($hash, $i, 2)) & 31;
  37.  
  38.                 //if 'i' is divisable by 8 (every 4 cycles) then we want to add "-"
  39.                 if ((($i % 8) == 0) && ($i > 0))
  40.                 {
  41.                         $key .= "-".substr($digilist, $nextdigit, 1);
  42.                 }
  43.                 else
  44.                 {
  45.                         $key .= substr($digilist, $nextdigit, 1);
  46.                 }
  47.         }
  48.  
  49.         $array = array($id, $key);
  50.         //return
  51.         return $array;
  52. }
  53. ?>
File Description
  • wat
  • PHP Code
  • 16 Oct-2018
  • 1.69 Kb
You can Share it: