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程序设计有所帮助。

相关文章

在MongoDB中模拟Auto Increment的php代码

代码大致如下所示: 复制代码 代码如下: <?php function generate_auto_increment_id($namespace, array $option =...

PHP命名空间定义与用法实例分析

PHP命名空间定义与用法实例分析

本文实例讲述了PHP命名空间定义与用法。分享给大家供大家参考,具体如下: php的命名空间的样式跟linux的路径很相似。 我们使用文件的路径作为命名空间。 定义命名空间 MVC\Mo...

手把手教你使用DedeCms V3的在线采集图文教程

手把手教你使用DedeCms V3的在线采集图文教程

这是我们要采集的目标网址-------------------------------------------------------------screen.width*0.7) {t...

php+redis实现注册、删除、编辑、分页、登录、关注等功能示例

php+redis实现注册、删除、编辑、分页、登录、关注等功能示例

本文实例讲述了php+redis实现注册、删除、编辑、分页、登录、关注等功能。分享给大家供大家参考,具体如下: 主要界面 连接redis redis.php <?ph...

搭建基于Docker的PHP开发环境的详细教程

搭建基于Docker的PHP开发环境的详细教程

现在很多开发者都使用Vagrant来管理他们的虚拟机开发环境,Vagrant确实很酷, 不过也有不少缺点(最主要的是它占用太多的资源)。在容器技术、Docker和更多类Docker技术出...