首页 >后端开发 >php教程 >通过正则表达式替换回调的内容标签

通过正则表达式替换回调的内容标签

WBOY
WBOY原创
2016-07-25 09:09:35928浏览
  1. function my_wp_plugin_tag_action($content,$tag,$function,$args = FALSE) {
  2. // match all regular expressions
  3. preg_match_all($tag,$content,$matches);
  4. if (count($matches)>0) {
  5. // filter duplicates
  6. $matches = array_unique($matches);
  7. // loop through
  8. $tag_results = array();
  9. $found_tags = array();
  10. foreach ($matches as $idx => $match) {
  11. //build arg array
  12. $full_tag = array_shift($match);
  13. //call function, adding function output and full tag text to replacement array
  14. $tag_results[] = my_wp_plugin_buffer_func($function,$match);
  15. $found_tags[] = $full_tag;
  16. }
  17. // replace all tags with corresponding text
  18. $content = str_replace($found_tags,$tag_results,$content);
  19. }
  20. return $content;
  21. }
复制代码


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn