I need a function in php that can generate a 5 char long string with numbers and a-z
What should I look into?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Other’s have already provided you with correct answers, but here’s a one-liner, just for the sake of it:
str_shufflerandomizes the above string, thensubstrtakes the first 5 letters of that shuffled string. Simple.As noted in comments for this answer, this function only generates strings that have only unique characters. If one would like to have the strings where even “aaaaa” is possible, here’s a little function that allows just that:
str_repeatrepeats the 0-9a-z string $len times, so every letter has an almost equal possibility for every position. (Read the comments on why only “almost”)