xml_helper.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 ExpressionEngine Dev Team
  9. * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
  10. * @license http://codeigniter.com/user_guide/license.html
  11. * @link http://codeigniter.com
  12. * @since Version 1.0
  13. * @filesource
  14. */
  15. // ------------------------------------------------------------------------
  16. /**
  17. * CodeIgniter XML Helpers
  18. *
  19. * @package CodeIgniter
  20. * @subpackage Helpers
  21. * @category Helpers
  22. * @author ExpressionEngine Dev Team
  23. * @link http://codeigniter.com/user_guide/helpers/xml_helper.html
  24. */
  25. // ------------------------------------------------------------------------
  26. /**
  27. * Convert Reserved XML characters to Entities
  28. *
  29. * @access public
  30. * @param string
  31. * @return string
  32. */
  33. if ( ! function_exists('xml_convert'))
  34. {
  35. function xml_convert($str, $protect_all = FALSE)
  36. {
  37. $temp = '__TEMP_AMPERSANDS__';
  38. // Replace entities to temporary markers so that
  39. // ampersands won't get messed up
  40. $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str);
  41. if ($protect_all === TRUE)
  42. {
  43. $str = preg_replace("/&(\w+);/", "$temp\\1;", $str);
  44. }
  45. $str = str_replace(array("&","<",">","\"", "'", "-"),
  46. array("&amp;", "&lt;", "&gt;", "&quot;", "&apos;", "&#45;"),
  47. $str);
  48. // Decode the temp markers back to entities
  49. $str = preg_replace("/$temp(\d+);/","&#\\1;",$str);
  50. if ($protect_all === TRUE)
  51. {
  52. $str = preg_replace("/$temp(\w+);/","&\\1;", $str);
  53. }
  54. return $str;
  55. }
  56. }
  57. // ------------------------------------------------------------------------
  58. /* End of file xml_helper.php */
  59. /* Location: ./system/helpers/xml_helper.php */