note 68217 modified in function.ord by danbrown

From: Date: Tue, 11 Oct 2011 16:10:17 +0000
Subject: note 68217 modified in function.ord by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-183801@lists.php.net to get a copy of this message
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 ?> --was-- You can use the following function to generate a random string between the lengths of $x and $y... $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 http://php.net/manual/en/function.ord.php

« previous php.notes (#183801) next »