Skip to content

Instantly share code, notes, and snippets.

@vlrmprjct
Created July 20, 2015 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vlrmprjct/34aba65aa368db4a5300 to your computer and use it in GitHub Desktop.
Save vlrmprjct/34aba65aa368db4a5300 to your computer and use it in GitHub Desktop.
Get a random alphanumeric string.
/**
* @param $prefix
* @param $suffix
* @param $size
*
* @return string
*/
private function randomKey($prefix, $suffix, $size)
{
$key = "";
$chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
for ($i = 0; $i < $size; $i++)
{
$key .= $chars[rand(0, strlen($chars) - 1)];
}
return $prefix . $key . $suffix;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment