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判断IP并转跳到相应城市分站的方法

本文实例讲述了PHP判断IP并转跳到相应城市分站的方法。分享给大家供大家参考。具体实现方法如下: <?php class QQWry{ var $Start...

php pcntl_fork和pcntl_fork 的用法

pcntl_fork()函数就是为当前的进程创建一个子进程。并且先运行父进程,返回的是子进程的PID,肯定大于零。在父进程的代码中可以用pcntl_fork(&$status)暂停父进程...

php通过文件头检测文件类型通用代码类(zip,rar等)

php通过文件头检测文件类型通用代码类(zip,rar等)

有时候我们这样做还不完善。可能有些人上存一些文件,但是他通过修改扩展名,让在我们的文件类型之内。 单实际访问时候又不能展示(因为扩展名与文件内容不符)。下面这个php类,可能能够给我们带...

PHP如何防止XSS攻击与XSS攻击原理的讲解

PHP如何防止XSS攻击与XSS攻击原理的讲解

XSS又称CSS,全称Cross SiteScript(跨站脚本攻击), XSS攻击类似于SQL注入攻击,是Web程序中常见的漏洞,XSS属于被动式且用于客户端的攻击方式,所以容易被忽略...

php microtime获取浮点的时间戳

一直以来用这个函数获取: 复制代码 代码如下: function microtime_float(){ list($usec, $sec) = explode(" ", microtim...