function _text_captcha_generate_nonsense_word in CAPTCHA 6
Same name and namespace in other branches
- 5.3 text_captcha/text_captcha.module \_text_captcha_generate_nonsense_word()
function for generating a random nonsense word of a given number of characters
1 call to _text_captcha_generate_nonsense_word()
- _text_captcha_generate_words in text_captcha/
text_captcha.user.inc - function for generating an array of words
File
- text_captcha/
text_captcha.user.inc, line 6
Code
function _text_captcha_generate_nonsense_word($characters) {
$vowels = "bcdfghjklmnpqrstvwxyz";
$consonants = "aeiou";
$vowel_max = strlen($vowels) - 1;
$consonant_max = strlen($consonants) - 1;
$word = '';
$o = mt_rand(0, 1);
// randomly start with vowel or consonants
for ($i = 0; $i < $characters; ++$i) {
if (($i + $o) % 2) {
$word .= $consonants[mt_rand(0, $consonant_max)];
}
else {
$word .= $vowels[mt_rand(0, $vowel_max)];
}
}
return $word;
}