note 73539 added to function.rand
| From: | www dot mrnaz dot com at osu1 dot php dot net | Date: | Wed, 28 Feb 2007 15:06:23 +0000 |
| Subject: | note 73539 added to function.rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-123950@lists.php.net to get a copy of this message | ||
This function uses rand() to create a random string of specified length from an optionally supplied
string of characters. It is good for generating passwords that only consist of alphanumeric
characters or codes that must consist of a defined character space such as for barcodes. It can also
be used to generate random hexadecimal numbers for things like encryption keys.
It is very fast, and allows for generation of strings of unlimited length.
<?php
function rand_string($len, $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789')
{
$string = '';
for ($i = 0; $i < $len; $i++)
{
$pos = rand(0, strlen($chars)-1);
$string .= $chars{$pos};
}
return $string;
}
?>
----
Server IP: 203.202.10.60
Probable Submitter: 203.214.77.49
----
Manual Page -- http://www.php.net/manual/en/function.rand.php
Edit -- https://master.php.net/note/edit/73539
Del: integrated -- https://master.php.net/note/delete/73539/integrated
Del: useless -- https://master.php.net/note/delete/73539/useless
Del: bad code -- https://master.php.net/note/delete/73539/bad+code
Del: spam -- https://master.php.net/note/delete/73539/spam
Del: non-english -- https://master.php.net/note/delete/73539/non-english
Del: in docs -- https://master.php.net/note/delete/73539/in+docs
Del: other reasons-- https://master.php.net/note/delete/73539
Reject -- https://master.php.net/note/reject/73539
Search -- https://master.php.net/manage/user-notes.php