admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 1 | <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); |
| 2 | /** |
| 3 | * Code Igniter |
| 4 | * |
| 5 | * An open source application development framework for PHP 4.3.2 or newer |
| 6 | * |
| 7 | * @package CodeIgniter |
| 8 | * @author Rick Ellis |
| 9 | * @copyright Copyright (c) 2006, pMachine, Inc. |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 10 | * @license http://www.codeignitor.com/user_guide/license.html |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 11 | * @link http://www.codeigniter.com |
| 12 | * @since Version 1.0 |
| 13 | * @filesource |
| 14 | */ |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 15 | |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 16 | // ------------------------------------------------------------------------ |
| 17 | |
| 18 | /** |
| 19 | * Code Igniter XML Helpers |
| 20 | * |
| 21 | * @package CodeIgniter |
| 22 | * @subpackage Helpers |
| 23 | * @category Helpers |
| 24 | * @author Rick Ellis |
| 25 | * @link http://www.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 |
| 36 | */ |
| 37 | function xml_convert($str) |
| 38 | { |
admin | 7acd581 | 2006-10-23 21:37:22 +0000 | [diff] [blame] | 39 | $temp = '__TEMP_AMPERSANDS__'; |
| 40 | |
| 41 | // Replace entities to temporary markers so that |
| 42 | // ampersands won't get messed up |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 43 | $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str); |
| 44 | $str = preg_replace("/&(\w+);/", "$temp\\1;", $str); |
| 45 | |
| 46 | $str = str_replace(array("&","<",">","\"", "'", "-"), |
| 47 | array("&", "<", ">", """, "'", "-"), |
| 48 | $str); |
admin | 7acd581 | 2006-10-23 21:37:22 +0000 | [diff] [blame] | 49 | |
| 50 | // Decode the temp markers back to entities |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 51 | $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); |
| 52 | $str = preg_replace("/$temp(\w+);/","&\\1;", $str); |
| 53 | |
| 54 | return $str; |
admin | e334c47 | 2006-10-21 19:44:22 +0000 | [diff] [blame] | 55 | } |
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 56 | |
| 57 | |
| 58 | ?> |