blob: dcfbbdf7402c00c53e75d1edc02467e79f54889d [file] [log] [blame]
Derek Allard2067d1a2008-11-13 22:59:24 +00001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2/**
3 * CodeIgniter
4 *
5 * An open source application development framework for PHP 4.3.2 or newer
6 *
7 * @package CodeIgniter
8 * @author ExpressionEngine Dev Team
Derek Jones7f3719f2010-01-05 13:35:37 +00009 * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
Derek Allard2067d1a2008-11-13 22:59:24 +000010 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
12 * @since Version 1.0
13 * @filesource
14 */
15
16// ------------------------------------------------------------------------
17
18/**
19 * CodeIgniter XML Helpers
20 *
21 * @package CodeIgniter
22 * @subpackage Helpers
23 * @category Helpers
24 * @author ExpressionEngine Dev Team
25 * @link http://codeigniter.com/user_guide/helpers/xml_helper.html
26 */
27
28// ------------------------------------------------------------------------
29
30/**
31 * Convert Reserved XML characters to Entities
32 *
33 * @access public
34 * @param string
35 * @return string
Barry Mienydd671972010-10-04 16:33:58 +020036 */
Derek Allard2067d1a2008-11-13 22:59:24 +000037if ( ! function_exists('xml_convert'))
38{
Derek Jones85b2bb72010-03-05 10:32:03 -060039 function xml_convert($str, $protect_all = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +000040 {
41 $temp = '__TEMP_AMPERSANDS__';
42
Barry Mienydd671972010-10-04 16:33:58 +020043 // Replace entities to temporary markers so that
44 // ampersands won't get messed up
Derek Allard2067d1a2008-11-13 22:59:24 +000045 $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str);
Barry Mienydd671972010-10-04 16:33:58 +020046
Derek Jones85b2bb72010-03-05 10:32:03 -060047 if ($protect_all === TRUE)
48 {
49 $str = preg_replace("/&(\w+);/", "$temp\\1;", $str);
50 }
Barry Mienydd671972010-10-04 16:33:58 +020051
Derek Allard2067d1a2008-11-13 22:59:24 +000052 $str = str_replace(array("&","<",">","\"", "'", "-"),
Derek Jones85b2bb72010-03-05 10:32:03 -060053 array("&amp;", "&lt;", "&gt;", "&quot;", "&apos;", "&#45;"),
54 $str);
Derek Allard2067d1a2008-11-13 22:59:24 +000055
Barry Mienydd671972010-10-04 16:33:58 +020056 // Decode the temp markers back to entities
Derek Allard2067d1a2008-11-13 22:59:24 +000057 $str = preg_replace("/$temp(\d+);/","&#\\1;",$str);
Barry Mienydd671972010-10-04 16:33:58 +020058
Derek Jones85b2bb72010-03-05 10:32:03 -060059 if ($protect_all === TRUE)
60 {
61 $str = preg_replace("/$temp(\w+);/","&\\1;", $str);
62 }
Barry Mienydd671972010-10-04 16:33:58 +020063
Derek Allard2067d1a2008-11-13 22:59:24 +000064 return $str;
Barry Mienydd671972010-10-04 16:33:58 +020065 }
Derek Allard2067d1a2008-11-13 22:59:24 +000066}
67
Derek Jones99111e32010-03-05 10:39:08 -060068// ------------------------------------------------------------------------
Derek Allard2067d1a2008-11-13 22:59:24 +000069
70/* End of file xml_helper.php */
Derek Jonesa3ffbbb2008-05-11 18:18:29 +000071/* Location: ./system/helpers/xml_helper.php */