You are here

function _phrase_captcha_word_question_double_occurence in CAPTCHA Pack 7

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

File

text_captcha/phrase_captcha/phrase_captcha.module, line 235

Code

function _phrase_captcha_word_question_double_occurence($words) {

  // Assure single occurence of each word
  $words = array_unique($words);

  // Pick a word
  $key = array_rand($words, 1);
  $answer = $words[$key];

  // Replace another word with it
  while (($pos = array_rand($words, 1)) == $key) {

    // NOP aka NOOP aka pass
  }
  array_splice($words, $pos, 1, $answer);
  $description = t('Which word occurs two times in the CAPTCHA phrase above?');
  return array(
    $words,
    $description,
    $answer,
  );
}