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实现的下载远程文件类定义与用法示例

本文实例讲述了PHP实现的下载远程文件类定义与用法。分享给大家供大家参考,具体如下: <?php /** * 下载远程文件类支持断点续传 */ class Http...

php浏览历史记录的方法

本文实例讲述了php浏览历史记录的方法。分享给大家供大家参考。具体实现方法如下: /** * 商品历史浏览记录 * $data 商品记录信息 */ private functi...

PHP中文处理 中文字符串截取(mb_substr)和获取中文字符串字数

一、中文截取:mb_substr() mb_substr( $str, $start, $length, $encoding ) $str,需要截断的字符串 $start,截断开始处,起...

PHP 导出Excel示例分享

下载PHPExcel_1.8.0_doc.zip http://phpexcel.codeplex.com/,将解压后的文件夹里的Classes上传到网站的根目录下,Classes目录内...

PHP ajax 异步执行不等待执行结果的处理方法

短地址生成应用中,要根据长地址生成网页快照,这个生成时间非瞬发,不可预估。 所以前台方面采用的方案一般为先展示生成的短地址,再定期AJAX轮查网页快照是否生成完毕。 So,PHP代码这里...