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中通过虚代理实现延迟加载的实现代码

这货是从 Martin 大神的《企业应用架构模式》中学到的,辅助 PHP 动态语言的特性,可以比 Java 轻松很多的实现延迟加载(LazyLoad)。基本原理是通过一个虚代理(Virt...

php session 写入数据库

本文实例介绍了php session 写入数据库的方法,分享给大家供大家参考,具体内容如下 <?php # # codeMaker Alpha 0.1.1 ( h...

深入PHP许愿墙模块功能分析

深入PHP许愿墙模块功能分析

许愿墙模块功能分析一,热点技术1,实现可拖放DOM技术移动许愿字条可拖放DOM模式(Draggable DOM pattern)的宗旨在于允许浏览者自己定义页面中各元素的位置,并且,只需...

PHP实现多文件上传的方法

本文实例讲述了PHP实现多文件上传的方法。分享给大家供大家参考。具体实现方法如下: <?php define('ROOT','D:/Program Files/www/...

php中生成随机密码的自定义函数代码

代码一:生成一个随机密码的函数,生成的密码为小写字母与数字的随机字符串,长度可自定义。相对来说,这个比较简单 复制代码 代码如下:<?php/* * php自动生成新密码...