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]);
51 for ($x=0; $x < strlen($string); $x++
) {
52 $return .= '&#x' . bin2hex($string[$x]) . ';';
58 for ($x=0; $x < strlen($string); $x++
) {
59 $return .= '&#' . ord($string[$x]) . ';';
64 // escape quotes and backslashes, newlines, etc.
65 return strtr($string, array('\\'=>'\\\\',"'"=>"\\'",'"'=>'\\"',"\r"=>'\\r',"\n"=>'\\n','</'=>'<\/'));
68 // safe way to display e-mail address on a web page
69 return str_replace(array('@', '.'),array(' [AT] ', ' [DOT] '), $string);
72 // escape non-standard chars, such as ms document quotes
74 for($_i = 0, $_len = strlen($string); $_i < $_len; $_i++
) {
75 $_ord = ord(substr($string, $_i, 1));
76 // non-standard char, escape it
78 $_res .= '&#' . $_ord . ';';
81 $_res .= substr($string, $_i, 1);
91 /* vim: set expandtab: */
This page took 0.447771 seconds and 4 git commands to generate.