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 面试碰到过的问题 在此做下记录

代码优化 复制代码 代码如下: for($i=0;$i<8;$i++){ array_push($week,$arr); } 复制代码 代码如下: for($i=0;$i<...

Discuz 模板语句分析及知识技巧

  一、模板 调用 比如在某个模板中,想调用另一个模板中的内容,可以用下面的语句: {template xxx} 假设,建立了一个新模板名字叫 "abc.htm" ,在后台 模...

PHP删除HTMl标签的实现代码

复制代码 代码如下:/** * 取出html标签 *  * @access public * @param string str * @...

使用纯php代码实现页面伪静态的方法

本文实例讲述了使用纯php代码实现页面伪静态的方法。分享给大家供大家参考。具体如下: if(1==URLROLE){ $nav=$_SERVER["REQUEST_URI"];...

php 中文处理函数集合

--- 空格 --- string GBspace(string) --------- 每个中文字之间加空格 string GBunspace(string) ------- 每个中文字...