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与数据格式进行转换类实例

本文实例讲述了PHP实现XML与数据格式进行转换类。分享给大家供大家参考。具体如下: <?php /** * xml2array() will convert the...

PHP PDOStatement:bindParam插入数据错误问题分析

废话不多说, 直接看代码:复制代码 代码如下:<?php$dbh = new PDO('mysql:host=localhost;dbname=test', "test");$qu...

Zend framework处理一个http请求的流程分析

Zend framework处理一个http请求的流程分析

  1, 首先是bootstrap过程,初始化程序里用到的资源 2, 创建一个Zend_Controller_Front实体,实现front controller模式,这个实...

如何利用php array_multisort函数 对数据库结果进行复杂排序

首先讲一下需求:数据库中有4个字段分别是id,volume,edition,name. 要求对查询结果按照volume+edition从大到小排序。下面将一下array_multisor...

PHP获取数组中单列值的方法

本文实例讲述了PHP获取数组中单列值的方法。分享给大家供大家参考,具体如下: PHP中获取数组中单列的值如下: 利用PHP中的数组函数 array_column():返回数组中某个单列的...