xml_helper.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * CodeIgniter
  4. *
  5. * An open source application development framework for PHP 5.1.6 or newer
  6. *
  7. * @package CodeIgniter
  8. * @author EllisLab Dev Team
  9. * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc.
  10. * @copyright Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/)
  11. * @license http://codeigniter.com/user_guide/license.html
  12. * @link http://codeigniter.com
  13. * @since Version 1.0
  14. * @filesource
  15. */
  16. // ------------------------------------------------------------------------
  17. /**
  18. * CodeIgniter XML Helpers
  19. *
  20. * @package CodeIgniter
  21. * @subpackage Helpers
  22. * @category Helpers
  23. * @author EllisLab Dev Team
  24. * @link http://codeigniter.com/user_guide/helpers/xml_helper.html
  25. */
  26. // ------------------------------------------------------------------------
  27. /**
  28. * Convert Reserved XML characters to Entities
  29. *
  30. * @access public
  31. * @param string
  32. * @return string
  33. */
  34. if ( ! function_exists('xml_convert'))
  35. {
  36. function xml_convert($str, $protect_all = FALSE)
  37. {
  38. $temp = '__TEMP_AMPERSANDS__';
  39. // Replace entities to temporary markers so that
  40. // ampersands won't get messed up
  41. $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str);
  42. if ($protect_all === TRUE)
  43. {
  44. $str = preg_replace("/&(\w+);/", "$temp\\1;", $str);
  45. }
  46. $str = str_replace(array("&","<",">","\"", "'", "-"),
  47. array("&amp;", "&lt;", "&gt;", "&quot;", "&apos;", "&#45;"),
  48. $str);
  49. // Decode the temp markers back to entities
  50. $str = preg_replace("/$temp(\d+);/","&#\\1;",$str);
  51. if ($protect_all === TRUE)
  52. {
  53. $str = preg_replace("/$temp(\w+);/","&\\1;", $str);
  54. }
  55. return $str;
  56. }
  57. }
  58. // ------------------------------------------------------------------------
  59. /* End of file xml_helper.php */
  60. /* Location: ./system/helpers/xml_helper.php */