note 101539 deleted from function.uniqid by danbrown
| From: | danbrown@php.net | Date: | Thu, 23 Dec 2010 13:39:52 +0000 |
| Subject: | note 101539 deleted from function.uniqid by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-175167@lists.php.net to get a copy of this message | ||
Note Submitter: mauroasprea at gmail dot com
----
super simple random string generator with custom length
<?php
function random_str($len = 4) {
$index = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$max = strlen($index);
$ret = '';
while (strlen($ret) < $len) {
$ret .= substr($index, rand(0, $max), 1);
}
return $ret;
}
?>