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 动态执行带有参数的类方法

官方手册给出了以下范例: 复制代码 代码如下:<?php // 使用了NameSpace的例子 namespace Foobar; class Foo { static publi...

使用NetBeans + Xdebug调试PHP程序的方法

使用NetBeans + Xdebug调试PHP程序的方法

按照网络上的资料配置好调试环境后实际试用了发现功能较为简陋,单文件调试还可,如果是跨文件调试项目就不那么舒服了,试用过程中因为DBGP插件也存在许多缺陷,烦恼不断,经常性地stack o...

解析php时间戳与日期的转换

大家也许对PHP时间戳已经有所了解,那么我们如何应用它来获取具体的日期呢?我们今天来为大家介绍一下PHP时间戳获取当前时期的具体方式。 实现功能:获取某个日期的时间戳,或获取某个时间...

php实现压缩多个CSS与JS文件的方法

本文实例讲述了php实现压缩多个CSS与JS文件的方法。分享给大家供大家参考。具体实现方法如下: 1. 压缩css 复制代码 代码如下:<?php  &...

深入探讨PHP中的内存管理问题

深入探讨PHP中的内存管理问题

一、 内存  在PHP中,填充一个字符串变量相当简单,这只需要一个语句"<?php $str = 'hello world '; ?>"即可,并且该字符串能够被自由地修改、拷贝和移动。而...