10 * Smarty escape modifier plugin
14 * Purpose: Escape the string according to escapement type
15 * @link http://smarty.php.net/manual/en/language.modifier.escape.php
16 * escape (Smarty online manual)
17 * @author Monte Ohrt <monte at ohrt dot com>
19 * @param html|htmlall|url|quotes|hex|hexentity|javascript
22 function smarty_modifier_escape($string, $esc_type = 'html', $char_set = 'ISO-8859-1')
26 return htmlspecialchars($string, ENT_QUOTES, $char_set);
29 return htmlentities($string, ENT_QUOTES, $char_set);
32 return rawurlencode($string);
35 return str_replace('%2F','/',rawurlencode($string));
38 // escape unescaped single quotes
39 return preg_replace("%(?<!\\\\)'%", "\\'", $string);
42 // escape every character into hex
44 for ($x=0; $x < strlen($string); $x++) {
45 $return .= '%' . bin2hex($string[$x]);
50 $return = str_replace('+','0',$string);
51 $return = preg_replace('/[^0-9]+/','',$return);
56 for ($x=0; $x < strlen($string); $x++) {
57 $return .= '&#x' . bin2hex($string[$x]) . ';';
63 for ($x=0; $x < strlen($string); $x++) {
64 $return .= '&#' . ord($string[$x]) . ';';
69 // escape quotes and backslashes, newlines, etc.
70 return strtr($string, array('\\'=>'\\\\',"'"=>"\\'",'"'=>'\\"',"\r"=>'\\r',"\n"=>'\\n','</'=>'<\/'));
73 // safe way to display e-mail address on a web page
74 return str_replace(array('@', '.'),array(' [AT] ', ' [DOT] '), $string);
77 // escape non-standard chars, such as ms document quotes
79 for($_i = 0, $_len = strlen($string); $_i < $_len; $_i++) {
80 $_ord = ord(substr($string, $_i, 1));
81 // non-standard char, escape it
83 $_res .= '&#' . $_ord . ';';
86 $_res .= substr($string, $_i, 1);
96 /* vim: set expandtab: */