blob: 5aa6de9ec0ce968cc999059e66dfab111b25368f [file] [log] [blame]
Derek Allardd2df9bc2007-04-15 17:41:17 +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
Derek Allard3d879d52008-01-18 19:41:32 +00008 * @author ExpressionEngine Dev Team
Derek Allardd2df9bc2007-04-15 17:41:17 +00009 * @copyright Copyright (c) 2006, EllisLab, Inc.
Derek Jones7a9193a2008-01-21 18:39:20 +000010 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
Derek Allardd2df9bc2007-04-15 17:41:17 +000012 * @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
Derek Allard3d879d52008-01-18 19:41:32 +000024 * @author ExpressionEngine Dev Team
Derek Jones7a9193a2008-01-21 18:39:20 +000025 * @link http://codeigniter.com/user_guide/helpers/xml_helper.html
Derek Allardd2df9bc2007-04-15 17:41:17 +000026 */
27
28// ------------------------------------------------------------------------
29
30/**
31 * Convert Reserved XML characters to Entities
32 *
33 * @access public
34 * @param string
35 * @return string
36 */
Derek Jones269b9422008-01-28 21:00:20 +000037if (! function_exists('xml_convert'))
Derek Allardd2df9bc2007-04-15 17:41:17 +000038{
Derek Jones269b9422008-01-28 21:00:20 +000039 function xml_convert($str)
40 {
41 $temp = '__TEMP_AMPERSANDS__';
Derek Allardd2df9bc2007-04-15 17:41:17 +000042
Derek Jones269b9422008-01-28 21:00:20 +000043 // Replace entities to temporary markers so that
44 // ampersands won't get messed up
45 $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str);
46 $str = preg_replace("/&(\w+);/", "$temp\\1;", $str);
Derek Allardd2df9bc2007-04-15 17:41:17 +000047
Derek Jones269b9422008-01-28 21:00:20 +000048 $str = str_replace(array("&","<",">","\"", "'", "-"),
49 array("&amp;", "&lt;", "&gt;", "&quot;", "&#39;", "&#45;"),
50 $str);
Derek Allardd2df9bc2007-04-15 17:41:17 +000051
Derek Jones269b9422008-01-28 21:00:20 +000052 // Decode the temp markers back to entities
53 $str = preg_replace("/$temp(\d+);/","&#\\1;",$str);
54 $str = preg_replace("/$temp(\w+);/","&\\1;", $str);
Derek Allardd2df9bc2007-04-15 17:41:17 +000055
Derek Jones269b9422008-01-28 21:00:20 +000056 return $str;
57 }
Derek Allardd2df9bc2007-04-15 17:41:17 +000058}
59
adminb0dd10f2006-08-25 17:25:49 +000060?>