You are here

function _phrase_captcha_generate_nonsense_word in CAPTCHA Pack 6

Same name and namespace in other branches
  1. 8 text_captcha/modules/phrase_captcha/phrase_captcha.module \_phrase_captcha_generate_nonsense_word()
  2. 5 text_captcha/phrase_captcha/phrase_captcha.module \_phrase_captcha_generate_nonsense_word()
  3. 7 text_captcha/phrase_captcha/phrase_captcha.module \_phrase_captcha_generate_nonsense_word()

function for generating a random nonsense word of a given number of characters

1 call to _phrase_captcha_generate_nonsense_word()
_phrase_captcha_generate_words in text_captcha/phrase_captcha/phrase_captcha.inc
function for generating an array of words

File

text_captcha/phrase_captcha/phrase_captcha.inc, line 6

Code

function _phrase_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 consonant
  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;
}