pouncer Posted May 14, 2007 Share Posted May 14, 2007 Hey guys, I want to generate a 32 length string which contains both number 0-9 and letter A-Z letters must be caps, any ideas guys? Link to comment https://forums.phpfreaks.com/topic/51335-generate-a-32-length-random-string/ Share on other sites More sharing options...
kenrbnsn Posted May 14, 2007 Share Posted May 14, 2007 Here's one method: <?php $str = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; $randstr = ''; while (strlen($randstr) < 32) $randstr .= $str{rand(0,strlen($str))}; echo '[' . strlen($randstr) . '] ' . $randstr; ?> Ken Link to comment https://forums.phpfreaks.com/topic/51335-generate-a-32-length-random-string/#findComment-252808 Share on other sites More sharing options...
chigley Posted May 14, 2007 Share Posted May 14, 2007 Another: <?php $random = rand(-1000000, 1000000); $md5 = md5($random); $string = strtoupper($md5); echo $string; ?> Link to comment https://forums.phpfreaks.com/topic/51335-generate-a-32-length-random-string/#findComment-252822 Share on other sites More sharing options...
pouncer Posted May 14, 2007 Author Share Posted May 14, 2007 perfect, thanks guys Link to comment https://forums.phpfreaks.com/topic/51335-generate-a-32-length-random-string/#findComment-252824 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.