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程序设计有所帮助。

相关文章

3种php生成唯一id的方法

小编在网上查了许多关于php生成唯一id方法的文章,发现有很多的方法,特整理本文与大家分享php生成唯一id的解决方法,希望大家喜欢。 1、md5(time() . mt_rand(1,...

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

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

PHP经典Redis操作类 调用方便,操作简单

/**  * redis操作类  * 说明,任何为false的串,存在redis中都是空串。  * 只有在key不存在时,才会返回fa...

php版微信公众号接口实现发红包的方法

php版微信公众号接口实现发红包的方法

本文实例讲述了php版微信公众号接口实现发红包的方法。分享给大家供大家参考,具体如下: 最近接到一个任务,需要用微信来给用户自动发红包。要完成这个任务需要这么已经一些物料 微信商户号,已...

php通过正则表达式记取数据来读取xml的方法

本文实例讲述了php通过正则表达式记取数据来读取xml的方法。分享给大家供大家参考。具体分析如下: xml源文件如下: <?xml version="1.0 enco...