johnmerlino Posted March 2, 2011 Share Posted March 2, 2011 Hey all, I'm looking to produce a random 10 character string like: abcABC0123 when the below method is called: <?php function randomize(){ $chars = explode(' ',(range("a","z"))) . explode(' ',(range("A","Z"))) . explode(' ',(range("0","9"))); $pass = ""; for($i = 0; $i < $len; $i += 1){ array_push($pass,$chars[rand(count($chars)-1)]); } return $pass; } var_dump(randomize(10)); ?> But the randomize method is not returning desired result. Any idea what I'm doing wrong? Thanks for response. Quote Link to comment Share on other sites More sharing options...
sunfighter Posted March 2, 2011 Share Posted March 2, 2011 I ran the code and received this error: Warning: explode() expects parameter 2 to be string, array given ....... That's what your doing wrong. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 2, 2011 Share Posted March 2, 2011 Try this for your function: <?php function randomize(){ $chars = array_merge(range("a","z"),range("A","Z"),range("0","9")); shuffle($chars); return implode('',array_slice($chars,0,10)); } echo randomize(); ?> Ken 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.