Automatically exported from code.google.com/p/planningalerts
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

modifier.regex_replace.php 900 B

17 년 전
1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. /**
  3. * Smarty plugin
  4. * @package Smarty
  5. * @subpackage plugins
  6. */
  7. /**
  8. * Smarty regex_replace modifier plugin
  9. *
  10. * Type: modifier<br>
  11. * Name: regex_replace<br>
  12. * Purpose: regular expression search/replace
  13. * @link http://smarty.php.net/manual/en/language.modifier.regex.replace.php
  14. * regex_replace (Smarty online manual)
  15. * @author Monte Ohrt <monte at ohrt dot com>
  16. * @param string
  17. * @param string|array
  18. * @param string|array
  19. * @return string
  20. */
  21. function smarty_modifier_regex_replace($string, $search, $replace)
  22. {
  23. if (preg_match('!([a-zA-Z\s]+)$!s', $search, $match) && (strpos($match[1], 'e') !== false)) {
  24. /* remove eval-modifier from $search */
  25. $search = substr($search, 0, -strlen($match[1])) . preg_replace('![e\s]+!', '', $match[1]);
  26. }
  27. return preg_replace($search, $replace, $string);
  28. }
  29. /* vim: set expandtab: */
  30. ?>