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的4种常见运行方式

SAPI:Server Application Programming Interface服务端应用编程端口。他就是php与其他应用交互的接口,php脚本要执行有很多中方式,通过web服...

比较简单实用的PHP无限分类源码分享(思路不错)

下面一段代码是创建相应数据库的sql代码:复制代码 代码如下: //////////////   //////无限分类的数据库设计及样例 &nbs...

如何使用php输出时间格式

复制代码 代码如下:<?date_default_timezone_set("ETC/GMT-8");$tm=time();echo date("Y-m-d h:i  a...

require(),include(),require_once()和include_once()区别

我把这两个语句放在一起介绍,读者可以比较学习。 1.require()语句 require()语句用于指定的文件代替语句本身,就象C语言中的include()语句一样。如果php配置文件...

PHP简单实现解析xml为数组的方法

本文实例讲述了PHP简单实现解析xml为数组的方法。分享给大家供大家参考,具体如下: 最近想要做一个插件机制,需要用到xml,在解析xml时候需要转换为数组,特意记录一个此种解析方式 x...