blob: 0cf8f13dc195bd83c21d48a9ae7f84fc57876146 [file] [log] [blame]
Derek Jones37f4b9c2011-07-01 17:56:50 -05001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Greg Aker741de1c2010-11-10 14:52:57 -06005 * An open source application development framework for PHP 5.1.6 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
8 *
9 * Licensed under the Open Software License version 3.0
10 *
11 * This source file is subject to the Open Software License (OSL 3.0) that is
12 * bundled with this package in the files license.txt / license.rst. It is
13 * also available through the world wide web at this URL:
14 * http://opensource.org/licenses/OSL-3.0
15 * If you did not receive a copy of the license and are unable to obtain it
16 * through the world wide web, please send an email to
17 * licensing@ellislab.com so we can send you a copy immediately.
18 *
Derek Allard2067d1a2008-11-13 22:59:24 +000019 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
21 * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
22 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Derek Allard2067d1a2008-11-13 22:59:24 +000023 * @link http://codeigniter.com
24 * @since Version 1.0
25 * @filesource
26 */
27
28// ------------------------------------------------------------------------
29
30/**
31 * CodeIgniter XML Helpers
32 *
33 * @package CodeIgniter
34 * @subpackage Helpers
35 * @category Helpers
Derek Jonesf4a4bd82011-10-20 12:18:42 -050036 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000037 * @link http://codeigniter.com/user_guide/helpers/xml_helper.html
38 */
39
40// ------------------------------------------------------------------------
41
42/**
43 * Convert Reserved XML characters to Entities
44 *
45 * @access public
46 * @param string
47 * @return string
Barry Mienydd671972010-10-04 16:33:58 +020048 */
Derek Allard2067d1a2008-11-13 22:59:24 +000049if ( ! function_exists('xml_convert'))
50{
Derek Jones85b2bb72010-03-05 10:32:03 -060051 function xml_convert($str, $protect_all = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +000052 {
53 $temp = '__TEMP_AMPERSANDS__';
54
Barry Mienydd671972010-10-04 16:33:58 +020055 // Replace entities to temporary markers so that
56 // ampersands won't get messed up
Derek Allard2067d1a2008-11-13 22:59:24 +000057 $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str);
Barry Mienydd671972010-10-04 16:33:58 +020058
Derek Jones85b2bb72010-03-05 10:32:03 -060059 if ($protect_all === TRUE)
60 {
Derek Jones37f4b9c2011-07-01 17:56:50 -050061 $str = preg_replace("/&(\w+);/", "$temp\\1;", $str);
Derek Jones85b2bb72010-03-05 10:32:03 -060062 }
Barry Mienydd671972010-10-04 16:33:58 +020063
Derek Allard2067d1a2008-11-13 22:59:24 +000064 $str = str_replace(array("&","<",">","\"", "'", "-"),
Derek Jones85b2bb72010-03-05 10:32:03 -060065 array("&amp;", "&lt;", "&gt;", "&quot;", "&apos;", "&#45;"),
66 $str);
Derek Allard2067d1a2008-11-13 22:59:24 +000067
Barry Mienydd671972010-10-04 16:33:58 +020068 // Decode the temp markers back to entities
Derek Allard2067d1a2008-11-13 22:59:24 +000069 $str = preg_replace("/$temp(\d+);/","&#\\1;",$str);
Barry Mienydd671972010-10-04 16:33:58 +020070
Derek Jones85b2bb72010-03-05 10:32:03 -060071 if ($protect_all === TRUE)
72 {
73 $str = preg_replace("/$temp(\w+);/","&\\1;", $str);
74 }
Barry Mienydd671972010-10-04 16:33:58 +020075
Derek Allard2067d1a2008-11-13 22:59:24 +000076 return $str;
Barry Mienydd671972010-10-04 16:33:58 +020077 }
Derek Allard2067d1a2008-11-13 22:59:24 +000078}
79
Derek Jones99111e32010-03-05 10:39:08 -060080// ------------------------------------------------------------------------
Derek Allard2067d1a2008-11-13 22:59:24 +000081
82/* End of file xml_helper.php */
Derek Jonesa3ffbbb2008-05-11 18:18:29 +000083/* Location: ./system/helpers/xml_helper.php */