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程序设计有所帮助。

相关文章

详解WordPress中用于合成数组的wp_parse_args()函数

wp_parse_args() 函数是 WordPress 核心经常用到的函数,它的用途很多,但最主要用来给一个数组参数(args)绑定默认值。 因为 wp_parse_args() 函...

php中使用parse_url()对网址进行解析的实现代码(parse_url详解)

PHP 解析 URL函数: parse_url详解 parse_url — 解析 URL,返回其组成部分 说明 array parse_url ( string $url ) 本函数解析...

MayFish PHP的MVC架构的开发框架

MayFish PHP的MVC架构的开发框架

框架工作流程: 加载框架文件》加载参数设置对象》进行初始化设置》加载项目设置参数》获取控制器及控制器方法》执行控制器事件 使用实例为: 复制代码 代码如下: <?php class...

php添加文章时生成静态HTML文章的实现代码

php添加文章时生成静态HTML文章的实现代码

PHP生成静态文章HTML,有批量的生成,但比较标准的应该是在添加文章时就生成HTML文章,编辑时再重新生成HTML文章,删除文章时同样也样删除多余出来的HTML文章,这时批量生成就显得...

详解WordPress开发中get_header()获取头部函数的用法

函数意义详解 从当前主题调用header.php文件。是不是很简单?好吧,如果你是新手的话这里要提醒一下,这里的get和get_children()、get_category中的get略...