70 * @return string The html string71 */72 static public function encode($string, $keepTags = true) {73 if($keepTags) {74 return stripslashes(implode('', preg_replace_callback('/^([^<].+[^>])$/', create_function('$match', 'return htmlentities($match[1], ENT_COMPAT, "utf-8");'), preg_split('/(<.+?>)/', $string, -1, PREG_SPLIT_DELIM_CAPTURE))));75 } else {76 return htmlentities($string, ENT_COMPAT, 'utf-8');77 }78 }79