You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

shared.escape_special_chars.php 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * Smarty shared plugin
  4. *
  5. * @package Smarty
  6. * @subpackage PluginsShared
  7. */
  8. if (version_compare(PHP_VERSION, '5.2.3', '>=')) {
  9. /**
  10. * escape_special_chars common function
  11. * Function: smarty_function_escape_special_chars<br>
  12. * Purpose: used by other smarty functions to escape
  13. * special chars except for already escaped ones
  14. *
  15. * @author Monte Ohrt <monte at ohrt dot com>
  16. *
  17. * @param string $string text that should by escaped
  18. *
  19. * @return string
  20. */
  21. function smarty_function_escape_special_chars($string)
  22. {
  23. if (!is_array($string)) {
  24. $string = htmlspecialchars($string, ENT_COMPAT, Smarty::$_CHARSET, false);
  25. }
  26. return $string;
  27. }
  28. } else {
  29. /**
  30. * escape_special_chars common function
  31. * Function: smarty_function_escape_special_chars<br>
  32. * Purpose: used by other smarty functions to escape
  33. * special chars except for already escaped ones
  34. *
  35. * @author Monte Ohrt <monte at ohrt dot com>
  36. *
  37. * @param string $string text that should by escaped
  38. *
  39. * @return string
  40. */
  41. function smarty_function_escape_special_chars($string)
  42. {
  43. if (!is_array($string)) {
  44. $string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string);
  45. $string = htmlspecialchars($string);
  46. $string = str_replace(array('%%%SMARTY_START%%%', '%%%SMARTY_END%%%'), array('&', ';'), $string);
  47. }
  48. return $string;
  49. }
  50. }