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

yipeiwu_com6年前PHP代码库

本文实例讲述了PHP实现通过正则表达式替换回调的内容标签。分享给大家供大家参考。具体实现方法如下:

function my_wp_plugin_tag_action($content,$tag,$function,$args = FALSE) {
 // match all regular expressions
 preg_match_all($tag,$content,$matches);
 if (count($matches)>0) {
  // filter duplicates
  $matches = array_unique($matches);
  // loop through
  $tag_results = array();
  $found_tags = array();
  foreach ($matches as $idx => $match) {
   //build arg array
   $full_tag = array_shift($match);
   //call function, adding function output and full tag text to replacement array
   $tag_results[] = my_wp_plugin_buffer_func($function,$match);
   $found_tags[] = $full_tag;
  }
  // replace all tags with corresponding text
  $content = str_replace($found_tags,$tag_results,$content);
 }
 return $content;
}

希望本文所述对大家的php程序设计有所帮助。

相关文章

PHP curl 获取响应的状态码的方法

PHP curl可以从服务器端模拟一个http请求,例如抓取网页、模拟登陆等。根据选项设置,可以在curl_exec的返回结果中获取到响应头和body,但这没有响应的状态吗。想要获取状态...

PHP观察者模式示例【Laravel框架中有用到】

本文实例讲述了PHP观察者模式。分享给大家供大家参考,具体如下: <?php //观察者模式 //抽象主题类 interface Subject { public...

PHP中session变量的销毁

1.何为session?相当于一个客户端(可以是浏览器、app、ftp等其他,而且同一个浏览器多开几个又算是不同的客户端)对服务器的一个访问,这个期间服务器为此建立一个唯一的标示(ses...

PHP中函数gzuncompress无法使用的解决方法

前言 gzuncompress函数不是php自带的系统函数而是一个插件函数了所以要使用 gzuncompress函数我们必须安装一个插件,下面来看看PHP函数gzuncompress无法...

PHP 数据库树的遍历方法

代码如下: 复制代码 代码如下:<?php session_start(); define ('P_S', PATH_SEPARATOR); define ('ROOT', "./...