You are here

function _phrase_captcha_generate_nonsense_word in CAPTCHA Pack 8

Same name and namespace in other branches
  1. 5 text_captcha/phrase_captcha/phrase_captcha.module \_phrase_captcha_generate_nonsense_word()
  2. 6 text_captcha/phrase_captcha/phrase_captcha.inc \_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 chars.

1 call to _phrase_captcha_generate_nonsense_word()
_phrase_captcha_generate_words in text_captcha/modules/phrase_captcha/phrase_captcha.module
Function for generating an array of words.

File

text_captcha/modules/phrase_captcha/phrase_captcha.module, line 86
Implementation of a phrase based CAPTCHA, for use with the CAPTCHA module.

Code

function _phrase_captcha_generate_nonsense_word($characters) {
  $vowels = 'bcdfghjklmnpqrstvwxyz';
  $consonants = 'aeiou';
  $vowel_max = strlen($vowels) - 1;
  $consonant_max = strlen($consonants) - 1;
  $word = '';

  // Randomly start with vowel or consonant.
  $o = mt_rand(0, 1);
  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;
}