xml_helper.php

Go to the documentation of this file.
00001 <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
00002 /**
00003  * CodeIgniter
00004  *
00005  * An open source application development framework for PHP 4.3.2 or newer
00006  *
00007  * @package             CodeIgniter
00008  * @author              ExpressionEngine Dev Team
00009  * @copyright   Copyright (c) 2008, EllisLab, Inc.
00010  * @license             http://codeigniter.com/user_guide/license.html
00011  * @link                http://codeigniter.com
00012  * @since               Version 1.0
00013  * @filesource
00014  */
00015 
00016 // ------------------------------------------------------------------------
00017 
00018 /**
00019  * CodeIgniter XML Helpers
00020  *
00021  * @package             CodeIgniter
00022  * @subpackage  Helpers
00023  * @category    Helpers
00024  * @author              ExpressionEngine Dev Team
00025  * @link                http://codeigniter.com/user_guide/helpers/xml_helper.html
00026  */
00027 
00028 // ------------------------------------------------------------------------
00029 
00030 /**
00031  * Convert Reserved XML characters to Entities
00032  *
00033  * @access      public
00034  * @param       string
00035  * @return      string
00036  */     
00037 if ( ! function_exists('xml_convert'))
00038 {
00039         function xml_convert($str)
00040         {
00041                 $temp = '__TEMP_AMPERSANDS__';
00042 
00043                 // Replace entities to temporary markers so that 
00044                 // ampersands won't get messed up
00045                 $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str);
00046                 $str = preg_replace("/&(\w+);/",  "$temp\\1;", $str);
00047         
00048                 $str = str_replace(array("&","<",">","\"", "'", "-"),
00049                                                    array("&amp;", "&lt;", "&gt;", "&quot;", "&#39;", "&#45;"),
00050                                                    $str);
00051 
00052                 // Decode the temp markers back to entities             
00053                 $str = preg_replace("/$temp(\d+);/","&#\\1;",$str);
00054                 $str = preg_replace("/$temp(\w+);/","&\\1;", $str);
00055                 
00056                 return $str;
00057         }
00058 }
00059 
00060 
00061 /* End of file xml_helper.php */
00062 /* Location: ./system/helpers/xml_helper.php */