You are here

function unhtmlentities in Quiz 6.5

Same name and namespace in other branches
  1. 6.6 includes/moodle/question/format/webct/format.php \unhtmlentities()

@package questionbank @subpackage importexport

File

includes/moodle/question/format/webct/format.php, line 35

Code

function unhtmlentities($string) {
  $search = array(
    "'<script[?>]*?>.*?</script>'si",
    // remove javascript
    "'<[\\/\\!]*?[^<?>]*?>'si",
    // remove HTML tags
    "'([\r\n])[\\s]+'",
    // remove spaces
    "'&(quot|#34);'i",
    // remove HTML entites
    "'&(amp|#38);'i",
    "'&(lt|#60);'i",
    "'&(gt|#62);'i",
    "'&(nbsp|#160);'i",
    "'&(iexcl|#161);'i",
    "'&(cent|#162);'i",
    "'&(pound|#163);'i",
    "'&(copy|#169);'i",
    "'&#(\\d+);'e",
  );

  // Evaluate like PHP
  $replace = array(
    "",
    "",
    "\\1",
    "\"",
    "&",
    "<",
    "?>",
    " ",
    chr(161),
    chr(162),
    chr(163),
    chr(169),
    "chr(\\1)",
  );
  return preg_replace($search, $replace, $string);
}