Skip to content

Instantly share code, notes, and snippets.

@sas1ni69
Last active September 27, 2015 06:48
Show Gist options
  • Save sas1ni69/1228511 to your computer and use it in GitHub Desktop.
Save sas1ni69/1228511 to your computer and use it in GitHub Desktop.
Random String
public function generateString ($length = 8) {
string = "";
$possible = "012346789abcdfghjkmnpqrtvwxyzABCDFGHJKLMNPQRTVWXYZ";
$maxlength = strlen($possible);
if ($length > $maxlength) {
$length = $maxlength;
}
$i = 0;
while ($i < $length) {
$char = substr($possible, mt_rand(0, $maxlength-1), 1);
if (!strstr($string, $char)) {
$string .= $char;
$i++;
}
}
return $string;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment