Link to home
Start Free TrialLog in
Avatar of hankknight
hankknightFlag for Canada

asked on

PHP: 5 random characters

I want 5 random characters to be taken from these available options:
       ABCDEFGHJKLMNPQRSTUVWXYZ23456789

For example this could be randomly returned:
AAZB5

But this should never be returned:
I10O1
Avatar of Hugh McCurdy
Hugh McCurdy
Flag of United States of America image

This, slightly modified, might do what you want.

http://www.webtoolkit.info/php-random-password-generator.html
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hankknight

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;	

?>

Open in new window

Cool, I'll make a note.  I keep a copy of most of these things.