shared.escape_special_chars.php 751 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. /**
  3. * Smarty shared plugin
  4. * @package Smarty
  5. * @subpackage PluginsShared
  6. */
  7. /**
  8. * escape_special_chars common function
  9. *
  10. * Function: smarty_function_escape_special_chars<br>
  11. * Purpose: used by other smarty functions to escape
  12. * special chars except for already escaped ones
  13. * @author Monte Ohrt <monte at ohrt dot com>
  14. * @param string
  15. * @return string
  16. */
  17. function smarty_function_escape_special_chars($string)
  18. {
  19. if(!is_array($string)) {
  20. $string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string);
  21. $string = htmlspecialchars($string);
  22. $string = str_replace(array('%%%SMARTY_START%%%','%%%SMARTY_END%%%'), array('&',';'), $string);
  23. }
  24. return $string;
  25. }
  26. ?>