Skip to content

Instantly share code, notes, and snippets.

@vhdm
Last active September 6, 2015 21:33
Show Gist options
  • Save vhdm/1e2159c6336274afbbeb to your computer and use it in GitHub Desktop.
Save vhdm/1e2159c6336274afbbeb to your computer and use it in GitHub Desktop.
Generate random string
<?php
function random_string($len=20){
$randstr = '';
srand((double)microtime()*1000000);
for($i=0;$i<$len;$i++){
$n = rand(48,120);
while (($n >= 58 && $n <= 64) || ($n >= 91 && $n <= 96)){
$n = rand(48,120);
}
$randstr .= chr($n);
}
return $randstr;
}
echo random_string();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment