Source for file escape.php

Documentation is available at escape.php

  1. <?php
  2.  
  3. /**
  4.  * Applies various escaping schemes on the given string
  5.  * <pre>
  6.  *  * value : the string to process
  7.  *  * format : escaping format to use, valid formats are : html, htmlall, url, urlpathinfo, quotes, hex, hexentity, javascript and mail
  8.  *  * charset : character set to use for the conversion (applies to some formats only), defaults to the current Dwoo charset
  9.  * </pre>
  10.  * This software is provided 'as-is', without any express or implied warranty.
  11.  * In no event will the authors be held liable for any damages arising from the use of this software.
  12.  *
  13.  * This file is released under the LGPL
  14.  * "GNU Lesser General Public License"
  15.  * More information can be found here:
  16.  * {@link http://www.gnu.org/copyleft/lesser.html}
  17.  *
  18.  * @author     Jordi Boggiano <j.boggiano@seld.be>
  19.  * @copyright  Copyright (c) 2008, Jordi Boggiano
  20.  * @license    http://www.gnu.org/copyleft/lesser.html  GNU Lesser General Public License
  21.  * @link       http://dwoo.org/
  22.  * @version    0.9.1
  23.  * @date       2008-05-30
  24.  * @package    Dwoo
  25.  */
  26. function Dwoo_Plugin_escape(Dwoo $dwoo$value=''$format='html'$charset=null)
  27. {
  28.     if ($charset === null{
  29.         $charset $dwoo->getCharset();
  30.     }
  31.  
  32.     switch($format)
  33.     {
  34.  
  35.     case 'html':
  36.         return htmlspecialchars((string) $valueENT_QUOTES$charset);
  37.     case 'htmlall':
  38.         return htmlentities((string) $valueENT_QUOTES$charset);
  39.     case 'url':
  40.         return rawurlencode((string) $value);
  41.     case 'urlpathinfo':
  42.         return str_replace('%2F''/'rawurlencode((string) $value));
  43.     case 'quotes':
  44.         return preg_replace("#(?<!\\\\)'#""\\'"(string) $value);
  45.     case 'hex':
  46.         $out '';
  47.         $cnt strlen((string) $value);
  48.         for ($i=0$i $cnt$i++{
  49.             $out .= '%' bin2hex((string) $value[$i]);
  50.         }
  51.         return $out;
  52.     case 'hexentity':
  53.         $out '';
  54.         $cnt strlen((string) $value);
  55.         for ($i=0$i $cnt$i++)
  56.             $out .= '&#x' bin2hex((string) $value[$i]';';
  57.         return $out;
  58.     case 'javascript':
  59.         return strtr((string) $valuearray('\\'=>'\\\\',"'"=>"\\'",'"'=>'\\"',"\r"=>'\\r',"\n"=>'\\n','</'=>'<\/'));
  60.     case 'mail':
  61.         return str_replace(array('@''.')array('&nbsp;(AT)&nbsp;''&nbsp;(DOT)&nbsp;')(string) $value);
  62.     default:
  63.         $dwoo->triggerError('Escape\'s format argument must be one of : html, htmlall, url, urlpathinfo, hex, hexentity, javascript or mail, "'.$format.'" given.'E_USER_WARNING);
  64.  
  65.     }
  66. }

Documentation generated on Sat, 28 Jun 2008 01:38:21 +0200 by phpDocumentor 1.4.0