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

相关文章

CI框架中通过hook的方式实现简单的权限控制

根据自己的实际情况,需要两个文件,一个是权限控制类,Acl,另外一个是权限配置的文件acl.php放在了config这个目录下。 Acl这个类放在了application/hook/ac...

php中convert_uuencode()与convert_uuencode函数用法实例

本文实例讲述了php中convert_uuencode()与convert_uuencode函数用法。分享给大家供大家参考。具体分析如下: onvert_uudecode() 函数对 u...

php的4种常用运行方式详解

php的4种常用运行方式:CGI、FastCGI、APACHE2HANDLER、CLI。 1、CGI CGI即通用网关接口(common gatewag interface),它是一...

10款PHP开源商城系统汇总介绍

  在当今经济危机的大环境下,网上购物越来越来吃香,网上开店成本低,快捷方便,出名的电子商务网站有淘宝,拍拍,Ebay或是最新的百度有啊,这些网站都提供开店的机会,如果是想自己搭建购物平...

PHP 生成的XML以FLASH获取为乱码终极解决

经过探索最终解决。记录之,顺便也记录了通用解决方案。如果你也遇到XML<->FLASH乱码情况,可以速查: 1.确信XML绝对没有问题的情况: 首先,flash读取xml出现...