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? Quote Link to comment 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? Quote Link to comment 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> Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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> Quote Link to comment Share on other sites More sharing options...
jeeva Posted February 22, 2007 Author Share Posted February 22, 2007 thanks for all Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.