whats the best way to generate a random, alphanumeric, upper and lowercase string?
thanks
eric
| SitePoint Sponsor |
whats the best way to generate a random, alphanumeric, upper and lowercase string?
thanks
eric





mt_rand
Be sure to check out the examples in the documentation, as it shows you how to use this to generate a random string of letters and numbers.
Music Around The World - Collecting tips, trade
and want lists, album reviews, & more
Showcase your music collection on the Web



I normally use something like this:
PHP Code:function random_string($length) {
$array = array_merge(range('a','z'), range('A','Z'));
$string = '';
for($i=1;$i<=$length;$i++)
$string .= $array[mt_rand(0,51)];
return $string;
}
Codyrobert.com - Designer and Developer
that doesnt seem to generate any numbers. is it supposed to?Originally Posted by codyrockx



ah, forgot the numbersthen you'd change this line
PHP Code:$array = array_merge(range('a','z'), range('A','Z'), range(0,9));
Codyrobert.com - Designer and Developer
I use something like this to generate a random alphanumeric string.
Of course you can modify substr call to suit your needs.PHP Code:$string = substr(md5(uniqid(rand(),1)), 0, 5);
-- Jelena --
Bookmarks