6 * @subpackage PluginsShared
10 * escape_special_chars common function
11 * Function: smarty_function_escape_special_chars<br>
12 * Purpose: used by other smarty functions to escape
13 * special chars except for already escaped ones
15 * @author Monte Ohrt <monte at ohrt dot com>
17 * @param string $string text that should by escaped
21 function smarty_function_escape_special_chars($string)
23 if (!is_array($string)) {
24 if (version_compare(PHP_VERSION, '5.2.3', '>=')) {
25 $string = htmlspecialchars($string, ENT_COMPAT, Smarty::$_CHARSET, false);
27 $string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string);
28 $string = htmlspecialchars($string);
29 $string = str_replace(array('%%%SMARTY_START%%%', '%%%SMARTY_END%%%'), array('&', ';'), $string);