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用数组返回无限分类的列表数据的代码

复制代码 代码如下: /*—————————————————— */ //– 获取无限分类的列表数据 /*—————————————————— */ function get_sort...

php实现图片以base64显示的方法

本文实例讲述了php实现图片以base64显示的方法。分享给大家供大家参考,具体如下: 这里实现图片以字符串形式保存到网页,从而不需要再加载图片的功能。 这是在RFC2397中定义的Da...

PHP使用反射机制实现查找类和方法的所在位置

本文实例讲述了PHP使用反射机制实现查找类和方法的所在位置。分享给大家供大家参考,具体如下: //参数1是类名,参数2是方法名 $func = new ReflectionMetho...

PHP define函数的使用说明

PHP中预先定义好的常量: __FILE__ 当前正在处理的脚本文件名。如果使用在一个被包含的文件中,那么它的值就是这个被包含的文件,而不是包含它的文件名。 __LINE__ 正在处理的...

php简单统计字符串单词数量的方法

本文实例讲述了php简单统计字符串单词数量的方法。分享给大家供大家参考。具体实现方法如下: <?php function word_count($sentence...