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判断并删除空目录及空子目录的方法。分享给大家供大家参考。具体实现方法如下: 步骤如下: 1.遍历目录及子目录 2.使用 scandir 判断目录是否为空,为空则使用r...

不常用但很实用的PHP预定义变量分析

1. $php_errormsg — 前一个错误信息 <?php @strpos(); echo $php_errormsg; ?> 2.$htt...

ThinkPHP路由详解

有了基本配置,我们就可以来访问我们的应用默认首页了。进入到项目目录,可以直接使用PHP内置服务器来开始访问,比如: php -S localhost:8999 浏览器输入loc...

PHP 创建标签云函数代码

复制代码 代码如下: function getCloud( $data = array(), $minFontSize = 12, $maxFontSize = 30 ) { $mini...

PHP 生成的XML以FLASH获取为乱码终极解决

经过探索最终解决。记录之,顺便也记录了通用解决方案。如果你也遇到XML<->FLASH乱码情况,可以速查: 1.确信XML绝对没有问题的情况: 首先,flash读取xml出现...