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开发注意事项总结

1.使用内嵌的HTML代码,而不是PHP的echo语句。 因为PHP是一门嵌入式Web编程语言,可以将HTML代码和PHP代码相互嵌入。但是很多程序员担心在HTML代码中过多的使用”"嵌...

PHP数组排序之sort、asort与ksort用法实例

本文实例讲解了PHP数组排序中sort、asort与ksort的用法,供大家参考借鉴之用。具体实例如下所示: <?php $arr = array('d'=>'s...

linux下删除7天前日志的代码(php+shell)

PHP版本: 复制代码 代码如下: /** * 删除7天前的日志 * @param $logPath */ function del7daysAgoLog($logPath) { if(...

php进程(线程)通信基础之System V共享内存简单实例分析

php进程(线程)通信基础之System V共享内存简单实例分析

本文实例讲述了php进程(线程)通信基础之System V共享内存。分享给大家供大家参考,具体如下: PHP默认情况没有开启功能,要支持该功能在编译PHP的时候要加入下面几个选项&nbs...