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中判断文件存在是用file_exists还是is_file的整理

看了这篇PHP中file_exists与is_file,is_dir的区别的说法基本明白,PHP的 file_exists = is_dir + is_file。 写程序验证一下: 分别...

PHP入门教程之图像处理技巧分析

本文实例讲述了PHP图像处理。分享给大家供大家参考,具体如下: Demo1.php <?php //一般生成的图像可以是 png,jpg,gif,bmp //j...

php判断用户是否手机访问代码

随着移动设备的普及,网站也会迎来越来越多移动设备的访问。用适应PC的页面,很多时候对手机用户不友好,那么有些时候,我们需要判断用户是否用手机访问,如果是手机的话,就跳转到指定的手机友好页...

php array_slice函数的使用以及参数详解

复制代码 代码如下:<?php /* 用手册上的例子 */ $input = array ("a", "b", "c", "d", "e"); $output = array_sl...

让PHP支持断点续传的源码

比如第一次请求一个文件的从0到999字节,第二次请求1000到1999字节,以此类推,每次请求1000字节的内容,然后程序通过fseek函数去取得对应的文件位置,然后输出。 复制代码 代...