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 class test{ public $x=1; public $settin...

使用ThinkPHP自带的Http类下载远程图片到本地的实现代码

Http类在目录ThinkPHP/Lib/ORG/Net下面。接下来看看是如何调用的。 复制代码 代码如下: <?php import("Com.Buyback.QueryAmaz...

php中in_array函数用法探究

本文较为深入的探究了php中in_array函数用法。分享给大家供大家参考。具体如下: 今天突然想到php中的in_array函数有个其怪的用法,下面我们来看看这个用法,有需要的朋友简单...

php 方便水印和缩略图的图形类

复制代码 代码如下:<?php /* *@author    夜无眠    27262681@qq....

PHP 应用程序的安全 -- 不能违反的四条安全规则

大家都知道安全性是重要的,但是行业中的趋势是直到最后一刻才添加安全性。既然不可能完全保护 Web 应用程序,那么为什么要费这个劲儿呢,不是吗?不对。只需采用一些简单的...