当前位置:Gxlcms > PHP教程 > 通过正则表达式替换回调的内容标签

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

时间:2021-07-01 10:21:17 帮助过:3人阅读

<无详细内容>
  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. }

人气教程排行