Q:

Write a PHP function to create a human-readable random string for a captcha

0

Write a PHP function to create a human-readable random string for a captcha.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

<?php
  function random_string($length = 5)
{ 
$chars = 'bcdfghjklmnpqrstvwxyzaeiou';

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

return $result;
}
echo random_string();
?>

Sample Output:

rasyn

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now