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)
18 * @param html|htmlall|url|quotes|hex|hexentity|javascript
21 function smarty_modifier_escape($string, $esc_type = 'html')
25 return htmlspecialchars($string, ENT_QUOTES
);
28 return htmlentities($string, ENT_QUOTES
);
31 return urlencode($string);
34 // escape unescaped single quotes
35 return preg_replace("%(?<!\\\\)'%", "\\'", $string);
38 // escape every character into hex
40 for ($x=0; $x < strlen($string); $x++
) {
41 $return .= '%' . bin2hex($string[$x]);
47 for ($x=0; $x < strlen($string); $x++
) {
48 $return .= '&#x' . bin2hex($string[$x]) . ';';
53 // escape quotes and backslashes and newlines
54 return strtr($string, array('\\'=>'\\\\',"'"=>"\\'",'"'=>'\\"',"\r"=>'\\r',"\n"=>'\\n'));
61 /* vim: set expandtab: */