shared.escape_special_chars.php (1566B)
1 <?php 2 /** 3 * Smarty shared plugin 4 * 5 * @package Smarty 6 * @subpackage PluginsShared 7 */ 8 9 if (version_compare(PHP_VERSION, '5.2.3', '>=')) { 10 /** 11 * escape_special_chars common function 12 * Function: smarty_function_escape_special_chars<br> 13 * Purpose: used by other smarty functions to escape 14 * special chars except for already escaped ones 15 * 16 * @author Monte Ohrt <monte at ohrt dot com> 17 * 18 * @param string $string text that should by escaped 19 * 20 * @return string 21 */ 22 function smarty_function_escape_special_chars($string) 23 { 24 if (!is_array($string)) { 25 $string = htmlspecialchars($string, ENT_COMPAT, Smarty::$_CHARSET, false); 26 } 27 28 return $string; 29 } 30 } else { 31 /** 32 * escape_special_chars common function 33 * Function: smarty_function_escape_special_chars<br> 34 * Purpose: used by other smarty functions to escape 35 * special chars except for already escaped ones 36 * 37 * @author Monte Ohrt <monte at ohrt dot com> 38 * 39 * @param string $string text that should by escaped 40 * 41 * @return string 42 */ 43 function smarty_function_escape_special_chars($string) 44 { 45 if (!is_array($string)) { 46 $string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string); 47 $string = htmlspecialchars($string); 48 $string = str_replace(array('%%%SMARTY_START%%%', '%%%SMARTY_END%%%'), array('&', ';'), $string); 49 } 50 51 return $string; 52 } 53 }