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 json相关函数用法示例

本文实例讲述了php json相关函数用法。分享给大家供大家参考,具体如下: 函数列表: 函数 描述...

php中神奇的fastcgi_finish_request

听起来可能有些茫然,我们通过几个例子来说明一下: 复制代码 代码如下: <?php echo '例子:'; fastcgi_finish_request(); echo 'To b...

编写Smarty插件在模板中直接加载数据的详细介绍

之前使用smarty的时候,通常是在php程序端读取数据(一般从数据库),然后assign给模板的变量,才可以在前端使用这个变量。这样不是不好,只是数据多的时候php端的代码维护起来有点...

PHP使用array_fill定义多维数组的方法

本文实例讲述了PHP使用array_fill定义多维数组的方法。分享给大家供大家参考。具体分析如下: PHP中可以用多个array_fill嵌套完成多维数组的定义: $creatio...

PHP实现显示照片exif信息的方法

PHP编程可实现显示照片EXIF信息,显示图片中缩略图效果,其代码如下: <? /** * 获取图象信息的函数 * 一个全面获取图象信息的函数 * @access pu...