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创建无限级树型菜单

写递归函数,可考虑缓存,定义一些静态变量来存上一次运行的结果,多程序运行效率很有帮助.。 大概步骤如下: step1:到数据库取数据,放到一个数组, step2:把数据转化为一个树型状的...

PHP网站备份程序代码分享

PHP网站备份程序代码分享

效果图:PHP代码 复制代码 代码如下: <html> <head> <meta http-equiv="Content-Type" content="te...

php求数组全排列,元素所有组合的方法

本文实例讲述了php求数组全排列,元素所有组合的方法。分享给大家供大家参考,具体如下: <?php $source = array('pll','我','爱','你',...

dedecms后台验证码总提示错误的解决方法

直接用下面的代码,覆盖dede中的login.php即可复制代码 代码如下:<? require_once(dirname(__FILE__)."/../include/confi...

PHP从二维数组得到N层分类树的实现代码

公司的产品分类存在一张表内,以mid标识其父分类,需要得到有层次结构的数组,以备后续操作。 想了下,想了一会儿没想出不去重复读取数据库的方法或者不需要递归的操作。 数据源:(数据要求一维...