0) {
$listAnswerResults['words_with_bracket'] = $listWords[0];
// remove [ and ] in string
array_walk(
$listWords[0],
function (&$value, $key, $tabBlankChar) {
$trimChars = '';
for ($i = 0; $i < count($tabBlankChar); $i++) {
$trimChars .= $tabBlankChar[$i];
}
$value = trim($value, $trimChars);
$key = trim($key);
},
[$blankCharStart, $blankCharEnd]
);
$listAnswerResults['words'] = $listWords[0];
}
// Get all common words
$commonWords = api_preg_replace(
'/'.$blankCharStartForRegexp.'[^'.$blankCharEndForRegexp.']*'.$blankCharEndForRegexp.'/',
'::',
$listDoubleColon[0]
);
$listAnswerResults['common_words'] = explode('::', $commonWords);
return $listAnswerResults;
}
/**
* Escapes text used for question type Fill in the blanks.
*
* @param $inChar
*
* @return mixed|string
*/
function escapeForRegexp($inChar)
{
$listChars = [
".",
"+",
"*",
"?",
"[",
"^",
"]",
"$",
"(",
")",
"{",
"}",
"=",
"!",
">",
"|",
":",
"-",
")",
];
if (in_array($inChar, $listChars)) {
return "\\".$inChar;
} else {
return $inChar;
}
}
/**
* Clear the answer entered.
*
* @param string $answer
*
* @return string
*/
function clearStudentAnswer($answer)
{
$answer = api_html_entity_decode($answer);
$answer = api_preg_replace('/\s\s+/', ' ', $answer); // replace excess white spaces
$answer = str_replace(''', ''', $answer);
$answer = strtr($answer, array_flip(get_html_translation_table(HTML_ENTITIES, ENT_QUOTES)));
return trim($answer);
}
/**
* Remove all html tag.
*
* @param string $string The string to be stripped of HTML
*
* @return string clean of html tag
*/
function removeHtml($string)
{
$txt = str_replace("", "", $string);
$txt = str_replace("
", "", $txt);
$txt = str_replace("", "", $txt);
$txt = str_replace("", "", $txt);
$txt = str_replace("", "", $txt);
$txt = str_replace("", "", $txt);
$txt = str_replace("", "", $txt);
$txt = str_replace("", "", $txt);
$txt = strip_tags($txt);
$txt = str_replace(chr(13).chr(10), "", $txt);
$txt = str_replace(" ", " ", $txt);
$txt = str_replace("Á", "Á", $txt);
$txt = str_replace("á", "á", $txt);
$txt = str_replace("É", "É", $txt);
$txt = str_replace("é", "é", $txt);
$txt = str_replace("Í", "Í", $txt);
$txt = str_replace("í", "í", $txt);
$txt = str_replace("Ó", "Ó", $txt);
$txt = str_replace("ó", "ó", $txt);
$txt = str_replace("Ú", "Ú", $txt);
$txt = str_replace("ú", "ú", $txt);
$txt = str_replace("Ñ", "Ñ", $txt);
$txt = str_replace("ñ", "ñ", $txt);
$txt = str_replace("à", "à", $txt);
$txt = str_replace("À", "À", $txt);
$txt = str_replace("¡", "¡", $txt);
$txt = str_replace("·", "·", $txt);
$txt = str_replace("Ç", "Ç", $txt);
$txt = str_replace("ç", "ç", $txt);
$txt = str_replace(""", '"', $txt);
$txt = str_replace("ª", 'ª', $txt);
$txt = str_replace("º", 'º', $txt);
$txt = str_replace("&", '&', $txt);
$txt = str_replace("•", '•', $txt);
$txt = str_replace("¿", '¿', $txt);
$txt = str_replace("€", 'EUR', $txt);
$txt = str_replace("ü", 'ü', $txt);
$txt = str_replace("Ü", 'Ü', $txt);
$txt = str_replace("¨", '¨', $txt);
return $txt;
}
/**
* Remove all html tag.
*
* @param string $string The string to be stripped of accents
*
* @return string clean of html tag
*/
function removeQuotes($string)
{
$txt = str_replace(" ", " ", $string);
$txt = str_replace("Á", "Á", $txt);
$txt = str_replace("á", "á", $txt);
$txt = str_replace("É", "É", $txt);
$txt = str_replace("é", "é", $txt);
$txt = str_replace("Í", "Í", $txt);
$txt = str_replace("í", "í", $txt);
$txt = str_replace("Ó", "Ó", $txt);
$txt = str_replace("ó", "ó", $txt);
$txt = str_replace("Ú", "Ú", $txt);
$txt = str_replace("ú", "ú", $txt);
$txt = str_replace("Ñ", "Ñ", $txt);
$txt = str_replace("ñ", "ñ", $txt);
$txt = str_replace(""", '"', $txt);
$txt = str_replace("ª", 'ª', $txt);
$txt = str_replace("º", 'º', $txt);
$txt = str_replace("&", '&', $txt);
$txt = str_replace("•", '•', $txt);
$txt = str_replace("¿ &", '¿', $txt);
$txt = str_replace("à", "à", $txt);
$txt = str_replace("À", "À", $txt);
$txt = str_replace("¡", "¡", $txt);
$txt = str_replace("·", "·", $txt);
$txt = str_replace("Ç", "Ç", $txt);
$txt = str_replace("ç", "ç", $txt);
$txt = str_replace("€", 'EUR', $txt);
$txt = str_replace("ü", 'ü', $txt);
$txt = str_replace("Ü", 'Ü', $txt);
$txt = str_replace("uml;", '¨', $txt);
return $txt;
}