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 pear安装配置教程

什么是PEAR? PEAR是PHP扩展与应用库(the PHP Extension and Application Repository)的缩写。它是一个PHP扩展及应用的一个代码仓库,...

实例说明js脚本语言和php脚本语言的区别

js脚本语言和php脚本语言的区别是什么? 一句话: js是客户端脚本, 由浏览器执行。 php是服务端脚本, 由php服务执行, php脚本跟shell脚本(bash执行)颇为类似。...

PHP抽象类基本用法示例

本文实例讲述了PHP抽象类基本用法。分享给大家供大家参考,具体如下: <?php //抽象类像一个模板,供子类扩展(重写),抽象类里有普通方法(有方法体),也有抽象方法...

PHP图像处理技术实例总结【绘图、水印、验证码、图像压缩】

PHP图像处理技术实例总结【绘图、水印、验证码、图像压缩】

本文实例总结了PHP图像处理技术。分享给大家供大家参考,具体如下: 1、绘图 场景: 验证码、图像水印、图像压缩处理 php绘图坐标体系是从0,0点越向右值越大,越向下值越大 需要开启p...

PHP冒泡算法详解(递归实现)

实现 复制代码 代码如下: /*     冒泡算法(递归实现) */ function maoPao($array, $index=0) {  &...