PHP实现通过正则表达式替换回调的内容标签

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

相关文章

在Windows系统下使用PHP生成Word文档的教程

在Windows系统下使用PHP生成Word文档的教程

准备工作 首先,请确保在你的Windows系统中已经安装并配置好了一个典型的WAMP环境。由于Interop纯粹是一个Windows的特性,我们将在Windows平台下搭建Apache和...

PHP垃圾回收机制引用计数器概念分析

如果你安装了xdebug,就可以用xdebug_debug_zval()显示“zval”的信息了。如下: 复制代码 代码如下:<?php$str = "jb51.net";xdeb...

php横向重复区域显示二法

方法一. 注意这里有一个预先定义的图片记录集rsmpic 要横向重复的就是图片,请根据你的情况改为你的记录集名称.整齐地将横向重复内容放在一个表格内 <table width="1...

php获取网卡的MAC地址支持WIN/LINUX系统

复制代码 代码如下: <?php /** 获取网卡的MAC地址原码;目前支持WIN/LINUX系统 获取机器网卡的物理(MAC)地址 **/ class GetMacAddr{ v...

PHP中数组转换为SimpleXML教程

SimpleXML扩展函数提供了将XML转换为对象的工具集。这些对象处理普通的属性选择器和数组迭代器。 示例1: <?php // 将php数组转换为xml文档的代码...