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删除xml文档内容的方法

本文实例讲述了通过php删除xml文档内容的方法。分享给大家供大家参考。具体实现方法如下: 第一种情况:删除一个student节点 复制代码 代码如下:<?php //1、...

php基于dom实现读取图书xml格式数据的方法

本文实例讲述了php基于dom实现读取图书xml格式数据的方法。分享给大家供大家参考,具体如下: <?php $doc = new DOMDocument(); $...

PHP simple_html_dom.php+正则 采集文章代码

复制代码 代码如下: <?php //包含PHP Simple html Dom 类库文件 include_once('./simplehtmldom/simple_html_do...

php中将地址生成迅雷快车旋风链接的代码[测试通过]

在线演示地址:http://tools.jb51.net/tools/cs.php复制代码 代码如下:<?php function zhuanhuan() { $urlodd=ex...

php文件打包 下载之使用PHP自带的ZipArchive压缩文件并下载打包好的文件

php文件打包 下载之使用PHP自带的ZipArchive压缩文件并下载打包好的文件

总结:                     使用PHP下载文件的操作需要给出四个header(),可以参考我的另一篇博文:PHP如何实现下载功能超详细流程分析 计算文件的大小的时候,...