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

相关文章

php输出xml属性的方法

本文实例讲述了php输出xml属性的方法。分享给大家供大家参考。具体分析如下: 这段代码通过一个简单的范例演示了php如何读取xml文件并输出xml属性 <?php...

PHP fopen()和 file_get_contents()应用与差异介绍

复制代码 代码如下: $file=fopen("11.txt","r")or exit("Unable to open file!");//fopen打开文件,如果不存在就显示打不开。...

PHP_Cooikes不同页面无法传递的解决方法

这是我刚开始设置的cookies 复制代码 代码如下: setcookie("QQ_access_token",$_SESSION['access_token'],time()+3600...

php结合md5的加密解密算法实例

本文实例讲述了php结合md5的加密解密算法。分享给大家供大家参考,具体如下: <?php /* * Created on 2016-9-30 * */ functio...

php生成不重复随机数、数组的4种方法分享

php生成不重复随机数、数组的4种方法分享

下面写几种生成不重复随机数的方法,直接上代码吧 复制代码 代码如下: <?php define('RANDOM_MAX', 100); define('COUNT', 10...