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+ajax无刷新上传图片的实现方法

php+ajax无刷新上传图片的实现方法

本文实例讲述了php+ajax无刷新上传图片的实现方法。分享给大家供大家参考,具体如下: 1.引入文件 <!--图片上传begin--> <script type=...

php curl获取https页面内容,不直接输出返回结果的设置方法

使用php curl获取页面内容或提交数据, 有时候希望返回的内容作为变量储存, 而不是直接输出. 方法:设置curl的CURLOPT_RETURNTRANSFER选项为1或true....

php实现的统计字数函数定义与使用示例

本文实例讲述了php实现的统计字数函数定义与使用方法。分享给大家供大家参考,具体如下: <?php //函数定义: function countWords($str){...

php创建多级目录与级联删除文件的方法示例

本文实例讲述了php创建多级目录与级联删除文件的方法。分享给大家供大家参考,具体如下: 创建多级目录 mkdir函数只能创建一级的目录,如果我们想创建多级目录,则需要自己编写函数。...

php+ajax 文件上传代码实例

本文实例为大家分享了php+ajax 文件上传的具体代码,供大家参考,具体内容如下 html 代码 <form action="{pboot:form fcode=8}" m...