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的pcntl多进程用法实例

本文实例讲述了PHP的pcntl多进程用法。分享给大家供大家参考。具体分析如下: PHP使用PCNTL系列的函数也能做到多进程处理一个事务。比如我需要从数据库中获取80w条的数据,再做一...

PHP设计模式之责任链模式的深入解析

责任链模式,其目的是组织一个对象链处理一个如方法调用的请求。当ConcreteHandler(具体的处理程序)不知道如何满足来自Client的请求时,或它的目的不是这个时,它会委派给链中...

php中mt_rand()随机数函数用法

本文实例讲述了php中mt_rand()随机数函数用法。分享给大家供大家参考。具体分析如下: mt_rand() 使用 mersenne twister 算法返回随机整数. 语法:mt_...

php下尝试使用GraphicsMagick的缩略图功能

php下尝试使用GraphicsMagick的缩略图功能

常用的图片处理工具有GD,ImageMagick,GraphicsMagick等等。GD就是个阿斗,略过不提;ImageMagick是目前最流行的图片处理工具,它的功能非常丰富;Grap...

php eval函数用法 PHP中eval()函数小技巧

eval 将值代入字符串之中。 语法: void eval(string code_str); 传回值: 无 函式种类: 数据处理 内容说明 本函式可将字符串之中的变量值代入,通常用在处...