1

I am working from some code I found online but modified the function a little bit.
My function is

function generate_random_password($length=10)
{      
    $letters = 'bcdfghjklmnprstvwxzaeiou';

    $result = '';
    for($i=0; $i<$length; $i++)
    {
        $result =. ($i%2) ? $letters[mt_rand(19, 23)] : $letters[mt_rand(0, 18)];
    }

    return $result;
}

And I am echoing the random password like this

echo generate_random_password($_GET['length']);

The moment I added the mt_rand() in the $result line it stopped working. Any help would be appreciated. Thanks.

3
  • What error did you get? Commented Aug 21, 2013 at 3:48
  • 2
    When you give errors, don't paraphrase. Don't say "It's a parse error." Cut & paste the entire message so that we can see exactly what it says. Commented Aug 21, 2013 at 4:13
  • sorry about that now i know Commented Aug 21, 2013 at 4:17

2 Answers 2

4

The parse error is because of =.. It should be .= as follows:

$result .= ($i%2) ? $letters[mt_rand(19, 23)] : $letters[mt_rand(0, 18)];
Sign up to request clarification or add additional context in comments.

Comments

1

change .= instead of =.

$result .= ($i%2) ? $letters[mt_rand(19, 23)] : $letters[mt_rand(0, 18)];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.