You are here

function _cloze_get_question_chunks in Cloze 6

Same name and namespace in other branches
  1. 7 cloze.module \_cloze_get_question_chunks()
5 calls to _cloze_get_question_chunks()
ClozeQuestion::getAnsweringForm in ./cloze.classes.inc
Implementation of getAnsweringForm
ClozeQuestion::getNodeView in ./cloze.classes.inc
Implementation of getNodeView
_cloze_get_correct_answer in ./cloze.module
_cloze_get_correct_answer_chunks in ./cloze.module
_cloze_get_user_answer in ./cloze.module

File

./cloze.module, line 95

Code

function _cloze_get_question_chunks($question) {
  $chunks = array();
  while (strlen($question) > 0) {
    $match = FALSE;
    $pos = strpos($question, '[');
    if ($pos) {
      $substring = substr($question, 0, $pos - 1);
      $question = str_replace($substring, '', $question);
      $chunks[] = $substring;
      $match = TRUE;
    }
    $pos = strpos($question, ']');
    if ($pos !== FALSE) {
      $substring = substr($question, 0, $pos + 1);
      $question = str_replace($substring, '', $question);
      $chunks[] = $substring;
      $match = TRUE;
    }
    if (!$match) {
      $chunks[] = $question;
      $question = '';
    }
  }
  return $chunks;
}