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 不使用js实现页面跳转

在页面跳转的时候 一般使用都是js window.location.href 当然也可以使用复制代码 代码如下: <html> <head> <meta h...

php使用fopen创建utf8编码文件的方法

本文实例讲述了php使用fopen创建utf8编码文件的方法。分享给大家供大家参考。具体实现方法如下: 一般来说,如果我们直接使用fopen创建会发现文件编码都不是uft-8的了,那么如...

改写函数实现PHP二维/三维数组转字符串

由于工作需要,自己在手册给定的示例函数基础上改写出了这样一个函数,代码如下: 复制代码 代码如下: //将多维数组中所有的数值转换成字符串————》最多支持三维数组 function i...

php下连接mssql2005的代码

1.下载以下两个文件,放入php ext目录及system32 php_sqlsrv_52_ts_vc6.dll (线程安全) php_sqlsrv_52_nts_vc6.dll (非线...

PHP中用接口、抽象类、普通基类实现“面向接口编程”与“耦合方法”简述

复制代码 代码如下: <?php /* 边学边做的,为方便自己翻阅而发布,更为得到高人指点而发布,欢迎高手指点...... 【提示】本例通过测试无误 【情景设计】 模拟计算机主板I...