note 26821 deleted from control-structures.switch by peehaa

From: Date: Mon, 02 Dec 2013 09:11:55 +0000
Subject: note 26821 deleted from control-structures.switch by peehaa
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-197696@lists.php.net to get a copy of this message
Note Submitter: hexa at h3xa dot com ---- this is a simple function that returns a random string and uses switch to determine what kind of string you want. function r( [string prefix][,int type,][,int chars] ); type = 1 -> only numbers type = 2 -> only letters type = 3 -> both <?php function r($prefixo = "",$tipo = 3,$numcaracteres = 10) { switch ($tipo) { case 1: for ($x = 1; $x <= $numcaracteres; $x++) { $rnum .= chr(rand(48,57)); } return $prefixo . $rnum; break; case 2: for ($x = 1; $x <= $numcaracteres; $x++) { if (rand(1,2) == 1) { $rletras .= chr(rand(65,90)); } else { $rletras .= chr(rand(97,122)); } } return $prefixo . $rletras; break; case 3: for ($x = 1; $x <= $numcaracteres; $x++) { $r = rand(1,3); if ($r == 1) { $rstring .= chr(rand(65,90)); } elseif ($r == 2) { $rstring .= chr(rand(97,122)); } else { $rstring .= chr(rand(48,57)); } } return $prefixo . $rstring; break; } } ?>

« previous php.notes (#197696) next »