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单元测试框架PHPUnit用法详解

本文实例讲述了PHP单元测试框架PHPUnit用法。分享给大家供大家参考,具体如下: 以前在学习IOS开发时有专门写过Objective-C的单元测试的文章,IOS开发学习之单元测试,...

ie与session丢失(新窗口cookie丢失)实测及解决方案

今天在一个群中有人问到ie6中使用js的open,发现新窗口中并获取不到session, 经过使用下面的测试代码测试发现,是因为phpsessionid储存是进程级的有效期,只有同一进程...

php使用ZipArchive函数实现文件的压缩与解压缩

PHP ZipArchive 是PHP自带的扩展类,可以轻松实现ZIP文件的压缩和解压,使用前首先要确保PHP ZIP 扩展已经开启,具体开启方法这里就不说了,不同的平台开启PHP扩增的...

php文件夹的创建与删除方法

本文实例讲述了php文件夹的创建与删除方法。分享给大家供大家参考。具体如下: 1、创建文件夹 复制代码 代码如下:<?php //文件夹的创建 $file_path = "...

php 浮点数比较方法详解

浮点数运算精度问题 首先看一个例子: <?php $a = 0.1; $b = 0.9; $c = 1; var_dump(($a+$b)==$c); var_dump...