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+xml编程之SimpleXML的应用实例

本文实例讲述了php+xml编程之SimpleXML的应用。分享给大家供大家参考。具体如下: SimpleXML的核心思想:以面向对象的方式来操作xml文件,它会将xml文件的所有元素都...

php使用数组填充下拉列表框的方法

本文实例讲述了php使用数组填充下拉列表框的方法。分享给大家供大家参考。具体实现方法如下: <?php $data = array( (object)array("...

PHP递归实现层级树状展开

PHP递归实现层级树状展开

本文实例为大家分享了PHP递归实现层级树状展开的主要代码,供大家参考,具体内容如下 效果图: 实现代码: <?php $db = mysql_connect(...

用PHP实现递归循环每一个目录

函数的原理很简单,主要就是用了一下递归调用。 复制代码 代码如下: function file_list($path){ if ($handle = opendir($path)) {...

php获取文件名后缀常用方法小结

本文实例汇总了php获取文件名后缀常用方法。分享给大家供大家参考。具体实现方法如下: <?php header("Content-type:text/html;char...