[ Index ]
 

Code source de Joomla 1.0.13

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/includes/domit/ -> xml_domit_doctor.php (source)

   1  <?php
   2  /**
   3  * DOMIT! Doctor is a set of utilities for repairing malformed XML
   4  * @package domit-xmlparser
   5  * @copyright (C) 2004 John Heinstein. All rights reserved
   6  * @license http://www.gnu.org/copyleft/lesser.html LGPL License
   7  * @author John Heinstein <johnkarl@nbnet.nb.ca>
   8  * @link http://www.engageinteractive.com/domit/ DOMIT! Home Page
   9  * DOMIT! is Free Software
  10  **/
  11  
  12  /**
  13  * A (static) class containing utilities for repairing malformed XML
  14  *
  15  * @package domit-xmlparser
  16  * @author John Heinstein <johnkarl@nbnet.nb.ca>
  17  */
  18  class domit_doctor {
  19  
  20      /**
  21      * Looks for illegal ampersands and converts them to entities
  22      * @param string The xml text to be repaired
  23      * @return string The repaired xml text
  24      */
  25  	function fixAmpersands($xmlText) {
  26          $xmlText = trim($xmlText);
  27          $startIndex = -1;
  28          $processing = true;
  29          $illegalChar = '&';
  30  
  31          while ($processing) {
  32              $startIndex = strpos($xmlText, $illegalChar, ($startIndex + 1));
  33  
  34              if ($startIndex !== false) {
  35                  $xmlText = domit_doctor::evaluateCharacter($xmlText,
  36                                      $illegalChar, ($startIndex + 1));
  37              }
  38              else {
  39                  $processing = false;
  40              }
  41          }
  42  
  43          return $xmlText;
  44      } //fixAmpersands
  45  
  46      /**
  47      * Evaluates whether an ampersand should be converted to an entity, and performs the conversion
  48      * @param string The xml text
  49      * @param string The (ampersand) character
  50      * @param int The character index immediately following the ampersand in question
  51      * @return string The repaired xml text
  52      */
  53  	function evaluateCharacter($xmlText, $illegalChar, $startIndex) {
  54          $total = strlen($xmlText);
  55          $searchingForCDATASection = false;
  56  
  57          for ($i = $startIndex; $i < $total; $i++) {
  58              $currChar = substr($xmlText, $i, 1);
  59  
  60              if (!$searchingForCDATASection) {
  61                  switch ($currChar) {
  62                      case ' ':
  63                      case "'":
  64                      case '"':
  65                      case "\n":
  66                      case "\r":
  67                      case "\t":
  68                      case '&':
  69                      case "]":
  70                          $searchingForCDATASection = true;
  71                          break;
  72                      case ";":
  73                          return $xmlText;
  74                          break;
  75                  }
  76              }
  77              else {
  78                  switch ($currChar) {
  79                      case '<':
  80                      case '>':
  81                          return (substr_replace($xmlText, '&amp;',
  82                                          ($startIndex - 1) , 1));
  83                          break;
  84                      case "]":
  85                          return $xmlText;
  86                          break;
  87                  }
  88              }
  89          }
  90  
  91          return $xmlText;
  92      } //evaluateCharacter
  93  } //domit_doctor
  94  ?>


Généré le : Wed Nov 21 14:43:32 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics