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 JWT在web端中的使用方法教程

php JWT在web端中的使用方法教程

解释一下JWT JWT就是一个字符串,经过加密处理与校验处理的字符串,由三个部分组成。基于token的身份验证可以替代传统的cookie+session身份验证方法。三个部分分别如下:...

php源码的安装方法和实例

在官网下载源码包:https://www.php.net/downloads.php 步骤: 1、解压 命令:tar -xjvf php.tar.bz2 2、configure conf...

PHP+RabbitMQ实现消息队列的完整代码

前言 为什么使用RabbitMq而不是ActiveMq或者RocketMq? 首先,从业务上来讲,我并不要求消息的100%接受率,并且,我需要结合php开发,RabbitMq相较Rock...

php 实现进制转换(二进制、八进制、十六进制)互相转换实现代码

十进制转换为二进制、八进制、十六进制 从十进制向其它进制转换,用的是就用该数字不断除以要转换的进制数,读取余数。连接一起就可以了。 复制代码 代码如下: <?php /** *十进...

php发送html格式文本邮件的方法

本文实例讲述了php发送html格式文本邮件的方法。分享给大家供大家参考。具体实现方法如下: <?php $to = "simon@mailexample.com,...