fork download
  1. <?php
  2.  
  3. function createPassword($len = 8, $regex = "a-hjknp-zA-HJKNP-Z2-9")
  4. {
  5. $pass = null;
  6. $lchar = null;
  7. for ($i = 0; $i < $len; $i++) {
  8. $char = chr(mt_rand(48, 122));
  9. while (!preg_match("/[$regex]/", $char)) {
  10. if ($char == $lchar) {
  11. continue;
  12. }
  13. $char = chr(rand(48, 122));
  14. }
  15. $pass .= $char;
  16. $lchar = $char;
  17. }
  18.  
  19. return $pass;
  20. }
  21.  
  22. function createUUID($regex = "a-hjknp-zA-HJKNP-Z2-9")
  23. {
  24. return sprintf('%8s-%4s-%4s-%4s-%12s',
  25. createPassword(8, $regex),
  26. createPassword(4, $regex),
  27. createPassword(4, $regex),
  28. createPassword(4, $regex),
  29. createPassword(12, $regex)
  30. );
  31. }
  32.  
  33. echo createUUID();
Success #stdin #stdout 0.03s 25828KB
stdin
Standard input is empty
stdout
N5DA9WHj-7Tzc-EqCs-EJJN-xwHfScEGdzjX