note 68217 deleted from function.ord by hholzgra

From: Date: Thu, 02 Aug 2012 11:40:21 +0000
Subject: note 68217 deleted from function.ord by hholzgra
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-189602@lists.php.net to get a copy of this message
Note Submitter: phil (at) pchowtos (dot) co (dot) uk ---- You can use the following function to generate a random string between the lengths of $x and $y... <?php $x = 1; //minimum length $y = 10; //maximum length $len = rand($x,$y); //get a random string length for ($i = 0; $i < $len; $i++) { //loop $len no. of times $whichChar = rand(1,3); //choose if its a caps, lcase or num if ($whichChar == 1) { //it's a number $string .= chr(rand(48,57)); //randomly generate a num } elseif ($whichChar == 2) { //it's a small letter $string .= chr(rand(65,90)); //randomly generate an lcase } else { //it's a capital letter $string .= chr(rand(97,122)); //randomly generate a ucase } } echo $string; //echo out the generated string ?>

« previous php.notes (#189602) next »