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.gzcompress — Compress a string This function compress the given string usin...

php实现异步数据调用的方法

浏览器和服务器之间只有一种面向无连接的HTTP协议进行通讯的,面向无连接的程序的特点是客户端请求服务端,服务端根据请求返回相应的程序,不能保持持久连接。这样就出现了一个问题,一个客户端的...

简单的php 验证图片生成函数

复制代码 代码如下:<?php function yzm($name,$width,$height){ Header("Content-type: image/PNG"); sra...

PHP伪造来源HTTP_REFERER的方法实例详解

本文实例讲述了PHP伪造来源HTTP_REFERER的方法。分享给大家供大家参考。具体分析如下: 如今网络上十分流行论坛自动发帖机,自动顶贴机等,给众多论坛网站带来了大量的垃圾信息,许多...

浅谈php字符串反转 面试中经常遇到

1.单字节字符串反转 php提供了用于字符串反转的函数strrev() $str = 'abcdef'; echo strrev($str); 2.对于包含中文的多字节字符串需要用...