[ Index ]
 

Code source de Claroline 188

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/claroline/inc/lib/ -> xml.lib.php (source)

   1  <?php // $Id: xml.lib.php,v 1.1.2.2 2007/09/24 15:14:43 seb Exp $
   2  if ( count( get_included_files() ) == 1 ) die( '---' );
   3  /**
   4   * CLAROLINE
   5   * @version 1.8
   6   *
   7   * @copyright (c) 2001-2006 Universite catholique de Louvain (UCL)
   8   *
   9   * @license http://www.gnu.org/copyleft/gpl.html (GPL) GENERAL PUBLIC LICENSE
  10   *
  11   * @author claro team <cvs@claroline.net>
  12   */
  13  
  14  /**
  15   * transform all entities of $string to their hexadecimal representation
  16   *
  17   * @param $string string original string to entify
  18   * @param $quote_style string Constant choosen among ENT_COMPAT, ENT_QUOTES OR ENT_NOQUOTES (see htmlentities doc for more info)
  19   *
  20   * @return string entified string
  21   */
  22  function xmlentities( $string, $quote_style = ENT_QUOTES )
  23  {
  24      static $trans;
  25  
  26      // remove all html entities before xml encoding
  27      // must convert all quotes to avoid remaining html entity in code
  28      $string = html_entity_decode($string, ENT_QUOTES);
  29  
  30      // xml encoding
  31      if ( ! isset( $trans ) )
  32      {
  33          $trans = get_html_translation_table( HTML_ENTITIES, $quote_style );
  34          foreach ( $trans as $key => $value )
  35          {
  36              $trans[$key] = '&#'.ord( $key ).';';
  37          }
  38          // dont translate the '&' in case it is part of &xxx;
  39          $trans[chr(38)] = '&';
  40      }
  41  
  42      // after the initial translation, _do_ map standalone '&' into '&#38;'
  43      return preg_replace( "/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,3};)/"
  44          , "&#38;"
  45          , strtr( $string, $trans )
  46          );
  47  }
  48  
  49  ?>


Généré le : Thu Nov 29 14:38:42 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics