5 * @subpackage plugins
\r
10 * Smarty escape modifier plugin
\r
12 * Type: modifier<br>
\r
14 * Purpose: Escape the string according to escapement type
\r
15 * @link http://smarty.php.net/manual/en/language.modifier.escape.php
\r
16 * escape (Smarty online manual)
\r
18 * @param html|htmlall|url|quotes|hex|hexentity|javascript
\r
21 function smarty_modifier_escape($string, $esc_type = 'html')
\r
23 switch ($esc_type) {
\r
25 return htmlspecialchars($string, ENT_QUOTES);
\r
28 return htmlentities($string, ENT_QUOTES);
\r
31 return urlencode($string);
\r
34 // escape unescaped single quotes
\r
35 return preg_replace("%(?<!\\\\)'%", "\\'", $string);
\r
38 // escape every character into hex
\r
40 for ($x=0; $x < strlen($string); $x++) {
\r
41 $return .= '%' . bin2hex($string[$x]);
\r
47 for ($x=0; $x < strlen($string); $x++) {
\r
48 $return .= '&#x' . bin2hex($string[$x]) . ';';
\r
53 // escape quotes and backslashes and newlines
\r
54 return strtr($string, array('\\'=>'\\\\',"'"=>"\\'",'"'=>'\\"',"\r"=>'\\r',"\n"=>'\\n'));
\r
61 /* vim: set expandtab: */
\r