• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List

E:/E/GEAMP/www/openbiz/openbiz/others/Smarty/libs/plugins/modifier.escape.php

00001 <?php
00021 function smarty_modifier_escape($string, $esc_type = 'html')
00022 {
00023     switch ($esc_type) {
00024         case 'html':
00025             return htmlspecialchars($string, ENT_QUOTES);
00026 
00027         case 'htmlall':
00028             return htmlentities($string, ENT_QUOTES);
00029 
00030         case 'url':
00031             return rawurlencode($string);
00032 
00033         case 'quotes':
00034             // escape unescaped single quotes
00035             return preg_replace("%(?<!\\\\)'%", "\\'", $string);
00036 
00037         case 'hex':
00038             // escape every character into hex
00039             $return = '';
00040             for ($x=0; $x < strlen($string); $x++) {
00041                 $return .= '%' . bin2hex($string[$x]);
00042             }
00043             return $return;
00044             
00045         case 'hexentity':
00046             $return = '';
00047             for ($x=0; $x < strlen($string); $x++) {
00048                 $return .= '&#x' . bin2hex($string[$x]) . ';';
00049             }
00050             return $return;
00051 
00052         case 'decentity':
00053             $return = '';
00054             for ($x=0; $x < strlen($string); $x++) {
00055                 $return .= '&#' . ord($string[$x]) . ';';
00056             }
00057             return $return;
00058 
00059         case 'javascript':
00060             // escape quotes and backslashes, newlines, etc.
00061             return strtr($string, array('\\'=>'\\\\',"'"=>"\\'",'"'=>'\\"',"\r"=>'\\r',"\n"=>'\\n','</'=>'<\/'));
00062             
00063         case 'mail':
00064             // safe way to display e-mail address on a web page
00065             return str_replace(array('@', '.'),array(' [AT] ', ' [DOT] '), $string);
00066             
00067         case 'nonstd':
00068            // escape non-standard chars, such as ms document quotes
00069            $_res = '';
00070            for($_i = 0, $_len = strlen($string); $_i < $_len; $_i++) {
00071                $_ord = ord($string{$_i});
00072                // non-standard char, escape it
00073                if($_ord >= 126){
00074                    $_res .= '&#' . $_ord . ';';
00075                }
00076                else {
00077                    $_res .= $string{$_i};
00078                }
00079            }
00080            return $_res;
00081 
00082         default:
00083             return $string;
00084     }
00085 }
00086 
00087 /* vim: set expandtab: */
00088 
00089 ?>

Generated on Thu Apr 19 2012 17:01:16 for openbiz by  doxygen 1.7.2