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文本操作类, 封装处理,调用方便<?php    class CtbClass {   &nbs...

phpadmin如何导入导出大数据文件及php.ini参数修改

最近遇到了数据库过大的时候用phpadmin导入的问题,新版本的phpadmin导入限定是8M,老版本的可能2M,我的数据库有几十兆这可怎么办呢? 首先如果你有独立服务器或vps的话可以...

手把手教你使用DedeCms V3的在线采集图文教程

手把手教你使用DedeCms V3的在线采集图文教程

这是我们要采集的目标网址-------------------------------------------------------------screen.width*0.7) {t...

Discuz板块横排显示图片的实现方法

到你目前在使用的模板中寻找 discuz.htm 找到这一段代码: 复制代码 代码如下:<td width="$cat[forumcolwidth]" ...

PHP结合JQueryJcrop实现图片裁切实例详解

我们经常可以看到一些网站上有图片剪切的功能,或许你会觉得这一功能炫目华丽,神秘莫测!但是今天介绍的一款专用于图片裁切的插件jquery.Jcrop.min.js就将揭开图片剪切的神秘面纱...