note 100714 deleted from function.chr by nicobn
| From: | nicobn@php.net | Date: | Wed, 03 Nov 2010 21:55:06 +0000 |
| Subject: | note 100714 deleted from function.chr by nicobn | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-173733@lists.php.net to get a copy of this message | ||
Note Submitter: b54b9 at m36u86n45i45m dot net [Remove numbers]
Reason: 2
----
chr can be used to generate random strings too
<?php
function getRandomString($length = 6)
{
$map = Array("0" => Array("min" => 48, "max" => 57),
"1" => Array("min" => 65, "max" => 90), "2" =>
Array("min" => 97, "max" => 122));
$randString = "";
$current = 0;
for ($i = 0; $i < $length; $i++) {
$r = $map[mt_rand(0, 2)];
$randString .= chr(mt_rand($r["min"], $r["max"]));
}
return $randString;
}
?>