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工具型代码之印章抠图

能将白底红字的印章抠出来,用的是php,框架是laravel,其他框架请自行调节。扣其他颜色也可以,把里面的那段rgb参数判断改改就行了,最后抠出来的效果就是白底变透明,然后只留下红色的...

PHP创建桌面快捷方式的实例代码

复制代码 代码如下:$shortCut = "[InternetShortcut]URL=//www.jb51.netIDList=[{000214A0-0000-0000-C000-0...

php microtime获取浮点的时间戳

一直以来用这个函数获取: 复制代码 代码如下: function microtime_float(){ list($usec, $sec) = explode(" ", microtim...

php摘要生成函数(无乱码)

在使用的时候,得先把要生成摘要的内容strip_tags()一下,当然,你也可以把strip_tags()直接添加到函数中,我没有搞,自己添加吧。下面是函数: 复制代码 代码如下: fu...

利用php绘制饼状图的实现代码

drawPieImg()函数包含8个参数,$title为饼状图的标题;$dataArr为需要显示的数据数组;$labelArr为对应数据的标签分类数组;$colorArr为对应数据的绘图...