/[cvs]/nfo/php/libs/net.php.smarty/plugins/modifier.escape.php
ViewVC logotype

Contents of /nfo/php/libs/net.php.smarty/plugins/modifier.escape.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations)
Wed Oct 9 00:53:36 2002 UTC (21 years, 10 months ago) by cvsjoko
Branch: MAIN
no message

1 <?php
2
3 /*
4 * Smarty plugin
5 * ------------------------------------------------------------
6 * Type: modifier
7 * Name: escape
8 * Purpose: Escape the string according to escapement type
9 * ------------------------------------------------------------
10 */
11 function smarty_modifier_escape($string, $esc_type = 'html')
12 {
13 switch ($esc_type) {
14 case 'html':
15 return htmlspecialchars($string, ENT_QUOTES);
16
17 case 'htmlall':
18 return htmlentities($string, ENT_QUOTES);
19
20 case 'url':
21 return urlencode($string);
22
23 case 'quotes':
24 // escape unescaped single quotes
25 return preg_replace("%(?<!\\\\)'%", "\\'", $string);
26
27 case 'hex':
28 // escape every character into hex
29 for ($x=0; $x < strlen($string); $x++) {
30 $return .= '%' . bin2hex($string[$x]);
31 }
32 return $return;
33
34 case 'hexentity':
35 for ($x=0; $x < strlen($string); $x++) {
36 $return .= '&#x' . bin2hex($string[$x]) . ';';
37 }
38 return $return;
39
40 default:
41 return $string;
42 }
43 }
44
45 /* vim: set expandtab: */
46
47 ?>

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed