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多文件上传类。分享给大家供大家参考。具体如下: 复制代码 代码如下:<?php /* PHP多文件上传类 修改:Linvo 2008-2-15 */...

PHP获取一段文本显示点阵宽度和高度的方法

本文实例讲述了PHP获取一段文本显示点阵宽度和高度的方法。分享给大家供大家参考。具体如下: define("F_SIZE", 8); define("F_FONT", "arial....

php重定向的三种方法分享

一、用HTTP头信息 也就是用PHP的HEADER函数。PHP里的HEADER函数的作用就是向浏览器发出由HTTP协议规定的本来应该通过WEB服务器的控制指令,例如: 声明返回信息的类型...

php上传后台无法收到数据解决方法

php无法收到数据 form表单是很常用的html标签,它能为我们提交数据到服务器,上传文件等。有时后台程序却无法接收数据,下面看看解决方法吧。 一、$_POST接收不到数据,$_GET...

PHP 函数执行效率的小比较

就是把原来的数组中的数都“拆”成“单”位的。 下面是自己写的一个函数: 复制代码 代码如下: function splitStrToArray_mine($array) { $new_a...