PHP: Generate a random string.

Posted October 2nd, 2010


This function returns a random string composed of the characters contained within the "$string" variable of the function.

<?php
function randomString(){
  $string = "abcdefghijklmnopqrstuvwxyz0123456789";
  for($i=0;$i<25;$i++){
    $pos = rand(0,36);
    $str .= $string[$pos];
  }
  return $str
}
?>