fork download
  1. <?php
  2.  
  3. function getRandomString($length = 8) {
  4. $characters = str_split('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789');
  5.  
  6. for ($i = 0; $i < $length; $i++) {
  7. $rand = '';
  8. foreach (array_rand($characters, 5) as $k) $rand .= $characters[$k];
  9. $string[$i] = $rand;
  10. }
  11.  
  12. return $string;
  13. }
  14.  
  15. print_r(getRandomString());
Success #stdin #stdout 0.03s 52480KB
stdin
Standard input is empty
stdout
Array
(
    [0] => aBGKR
    [1] => fHKQS
    [2] => imw06
    [3] => nrxW7
    [4] => aflIZ
    [5] => lDFK2
    [6] => mP348
    [7] => kJRU7
)