6  * @subpackage PluginsModifier
 
  10  * Smarty escape modifier plugin
 
  14  * Purpose:  escape string for output
 
  16  * @link http://smarty.php.net/manual/en/language.modifier.count.characters.php count_characters (Smarty online manual)
 
  17  * @author Monte Ohrt <monte at ohrt dot com> 
 
  18  * @param string $string input string
 
  19  * @param string $esc_type escape type
 
  20  * @param string $char_set character set
 
  21  * @return string escaped input string
 
  23 function smarty_modifier_escape($string, $esc_type = 'html', $char_set = SMARTY_RESOURCE_CHAR_SET)
 
  27             return htmlspecialchars($string, ENT_QUOTES, $char_set);
 
  30             return htmlentities($string, ENT_QUOTES, $char_set);
 
  33             return rawurlencode($string);
 
  36             return str_replace('%2F', '/', rawurlencode($string));
 
  39             // escape unescaped single quotes
 
  40             return preg_replace("%(?<!\\\\)'%", "\\'", $string);
 
  43             // escape every character into hex
 
  45             for ($x = 0; $x < strlen($string); $x++) {
 
  46                 $return .= '%' . bin2hex($string[$x]);
 
  52             for ($x = 0; $x < strlen($string); $x++) {
 
  53                 $return .= '&#x' . bin2hex($string[$x]) . ';';
 
  59             for ($x = 0; $x < strlen($string); $x++) {
 
  60                 $return .= '&#' . ord($string[$x]) . ';';
 
  65             // escape quotes and backslashes, newlines, etc.
 
  66             return strtr($string, array('\\' => '\\\\', "'" => "\\'", '"' => '\\"', "\r" => '\\r', "\n" => '\\n', '</' => '<\/'));
 
  69           require_once(SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php');
 
  70           return smarty_mb_str_replace(array('@', '.'), array(' [AT] ', ' [DOT] '), $string);
 
  73             // escape non-standard chars, such as ms document quotes
 
  75             for($_i = 0, $_len = strlen($string); $_i < $_len; $_i++) {
 
  76                 $_ord = ord(substr($string, $_i, 1)); 
 
  77                 // non-standard char, escape it
 
  79                     $_res .= '&#' . $_ord . ';';
 
  81                     $_res .= substr($string, $_i, 1);