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原生函数一定好吗?

今天在阅读kohana源码中的Arr类的时候发现了这样一个函数 复制代码 代码如下:  /**   * Fill an array with a range of n...

php常用字符串查找函数strstr()与strpos()实例分析

本文实例讲述了php常用字符串查找函数strstr()与strpos()。分享给大家供大家参考,具体如下: 一句话使用strpos判断 ===或!==,这样才能达到预期的效果,性能要比s...

header与缓冲区之间的深层次分析

测试header之前有输出 <?php echo 'hello world!'; header('content-type: text/html;charset=ut...

php实现网页上一页下一页翻页过程详解

php实现网页上一页下一页翻页过程详解

前言 这几天做项目因为数据太多,需要对信息进行上下翻页展示,就自己写了翻页的代码 大致功能就是页面只显示几条信息,按上一页、下一页切换内容,当显示第一页时上一页和首页选项不可选,当页面加...

PHP函数extension_loaded()用法实例

本文实例讲述了PHP函数extension_loaded()用法。分享给大家供大家参考。具体分析如下: extension_loaded — 检查一个扩展是否已经加载 例如: 复制代码...