hankknight
asked on
PHP: 5 random characters
I want 5 random characters to be taken from these available options:
ABCDEFGHJKLMNPQRSTUVWXYZ23 456789
For example this could be randomly returned:
AAZB5
But this should never be returned:
I10O1
ABCDEFGHJKLMNPQRSTUVWXYZ23
For example this could be randomly returned:
AAZB5
But this should never be returned:
I10O1
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks. I made a slight correction to your code to prevent: "Uninitialized string offset: 32"
<?php
$srcstr = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
$dststr = "";
for($i = 0;$i < 5; $i++) {
$j = rand(0, strlen($srcstr) - 1);
$dststr .= $srcstr[$j];
}
echo $dststr;
?>
Cool, I'll make a note. I keep a copy of most of these things.
http://www.webtoolkit.info/php-random-password-generator.html