blob: 5242193aca2e9fc710f2adb9b9dc75ead10597a6 [file] [log] [blame]
Andrey Andreevdebcc362012-01-07 02:05:29 +02001<?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
Andrey Andreevdebcc362012-01-07 02:05:29 +02008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Andrey Andreevdebcc362012-01-07 02:05:29 +020010 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -050011 * 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
Greg Aker0defe5d2012-01-01 18:46:41 -060021 * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
Derek Jonesf4a4bd82011-10-20 12:18:42 -050022 * @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
Andrey Andreevdebcc362012-01-07 02:05:29 +020059 if ($protect_all == TRUE)
Derek Jones85b2bb72010-03-05 10:32:03 -060060 {
Andrey Andreevdebcc362012-01-07 02:05:29 +020061 $str = preg_replace('/&(\w+);/', "$temp\\1;", $str);
Derek Jones85b2bb72010-03-05 10:32:03 -060062 }
Barry Mienydd671972010-10-04 16:33:58 +020063
Andrey Andreevdebcc362012-01-07 02:05:29 +020064 $str = str_replace(array('&', '<', '>', '"', "'", '-'),
65 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
Andrey Andreevdebcc362012-01-07 02:05:29 +020069 $str = preg_replace('/$temp(\d+);/', '&#\\1;', $str);
Barry Mienydd671972010-10-04 16:33:58 +020070
Andrey Andreevdebcc362012-01-07 02:05:29 +020071 if ($protect_all == TRUE)
Derek Jones85b2bb72010-03-05 10:32:03 -060072 {
Andrey Andreevdebcc362012-01-07 02:05:29 +020073 return preg_replace("/$temp(\w+);/", '&\\1;', $str);
Derek Jones85b2bb72010-03-05 10:32:03 -060074 }
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 Allard2067d1a2008-11-13 22:59:24 +000080/* End of file xml_helper.php */
Andrey Andreevdebcc362012-01-07 02:05:29 +020081/* Location: ./system/helpers/xml_helper.php */