Skip to content

Instantly share code, notes, and snippets.

@dmdavis
Created May 3, 2012 14:13
Show Gist options
  • Select an option

  • Save dmdavis/2585915 to your computer and use it in GitHub Desktop.

Select an option

Save dmdavis/2585915 to your computer and use it in GitHub Desktop.
Random String (PHP)
<?php
/**
* Create a random string $l characters in length.
*
* @link http://www.php.net/manual/en/ref.strings.php#84888
* @param int $l number of characters (default: 10)
* @return string the random string
*/
function random_string($l = 10) {
$c = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxwz0123456789";
$s = '';
for(;$l > 0;$l--)
$s .= $c{rand(0,strlen($c))};
return str_shuffle($s);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment