首頁 >後端開發 >php教程 >透過正規表示式替換回呼的內容標籤

透過正規表示式替換回呼的內容標籤

WBOY
WBOY原創
2016-07-25 09:09:35929瀏覽
  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