--- nfo/php/libs/net.php.smarty/plugins/modifier.escape.php 2002/10/09 00:53:36 1.1 +++ nfo/php/libs/net.php.smarty/plugins/modifier.escape.php 2004/06/16 21:58:17 1.2 @@ -1,12 +1,22 @@ + * Name: escape
* Purpose: Escape the string according to escapement type - * ------------------------------------------------------------ + * @link http://smarty.php.net/manual/en/language.modifier.escape.php + * escape (Smarty online manual) + * @param string + * @param html|htmlall|url|quotes|hex|hexentity|javascript + * @return string */ function smarty_modifier_escape($string, $esc_type = 'html') { @@ -24,18 +34,50 @@ // escape unescaped single quotes return preg_replace("%(?'\\\\',"'"=>"\\'",'"'=>'\\"',"\r"=>'\\r',"\n"=>'\\n',''<\/')); + + case 'mail': + // safe way to display e-mail address on a web page + return str_replace(array('@', '.'),array(' [AT] ', ' [DOT] '), $string); - case 'hexentity': - for ($x=0; $x < strlen($string); $x++) { - $return .= '&#x' . bin2hex($string[$x]) . ';'; - } - return $return; + case 'nonstd': + // escape non-standard chars, such as ms document quotes + $_res = ''; + for($_i = 0, $_len = strlen($string); $_i < $_len; $_i++) { + $_ord = ord($string{$_i}); + // non-standard char, escape it + if($_ord >= 126){ + $_res .= '&#' . $_ord . ';'; + } + else { + $_res .= $string{$_i}; + } + } + return $_res; default: return $string;