jeeva Posted February 22, 2007 Share Posted February 22, 2007 hi frnds, can i generate random character by using php?. i can generate the random number by using rand() function but i can't able to generate the character. is there any function in php for this? any one can help me? Link to comment https://forums.phpfreaks.com/topic/39596-random-character/ Share on other sites More sharing options...
boo_lolly Posted February 22, 2007 Share Posted February 22, 2007 there are <i>plenty</i> of ways to do this. and i mean a LOT. first of all, do you want to generate only one random character? or a long string of random characters? Link to comment https://forums.phpfreaks.com/topic/39596-random-character/#findComment-191070 Share on other sites More sharing options...
effigy Posted February 22, 2007 Share Posted February 22, 2007 <pre> <?php $lc_letters = range('a', 'z'); $uc_letters = range('A', 'Z'); $numbers = range(0, 9); $pool = array_merge($uc_letters, $lc_letters, $numbers); for ($i = 0; $i <= 9; $i++) { echo $pool[array_rand($pool)]; } ?> </pre> Link to comment https://forums.phpfreaks.com/topic/39596-random-character/#findComment-191074 Share on other sites More sharing options...
jeeva Posted February 22, 2007 Author Share Posted February 22, 2007 i want to generate the 2 character Link to comment https://forums.phpfreaks.com/topic/39596-random-character/#findComment-191075 Share on other sites More sharing options...
kenrbnsn Posted February 22, 2007 Share Posted February 22, 2007 i want to generate the 2 character That doesn't make any sense. "The 2 character" what? Ken Link to comment https://forums.phpfreaks.com/topic/39596-random-character/#findComment-191079 Share on other sites More sharing options...
jeeva Posted February 22, 2007 Author Share Posted February 22, 2007 i want 2 character within A to Z Link to comment https://forums.phpfreaks.com/topic/39596-random-character/#findComment-191082 Share on other sites More sharing options...
mmarif4u Posted February 22, 2007 Share Posted February 22, 2007 Try this: <pre> <?php $lc_letters = range('a', 'z'); $uc_letters = range('A', 'Z'); //$numbers = range(0, 9); $pool = array_merge($uc_letters, $lc_letters); for ($i = 0; $i <= 1; $i++) { echo $pool[array_rand($pool)]; } ?> </pre> Link to comment https://forums.phpfreaks.com/topic/39596-random-character/#findComment-191084 Share on other sites More sharing options...
jeeva Posted February 22, 2007 Author Share Posted February 22, 2007 thanks for all Link to comment https://forums.phpfreaks.com/topic/39596-random-character/#findComment-191094 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.