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

相关文章

关于Laravel Service Provider开发设置延迟加载时遇到的问题详解

前言 本文主要介绍了关于Laravel Service Provider设置延迟加载时遇到的一些问题,之所有这篇文章,是因实际项目需求,近日在开发 laravel-database-lo...

PHP设计模式之观察者模式定义与用法分析

本文实例讲述了PHP设计模式之观察者模式定义与用法。分享给大家供大家参考,具体如下: 观察者模式 当一个对象的状态发生改变时,依赖他的对象会全部收到通知,并自动更新 场景:当一个事件发生...

PHP连接sql server 2005环境配置及问题解决

一、Windows下PHP连接SQLServer 2005 设定:安装的Windows操作系统(Win7 或XP均可,其他系统暂未测试),在C盘下;PHP的相关文件位于c:/PHP下面,...

php代码中使用换行及(\n或\r\n和br)的应用

代码a: 复制代码 代码如下: <?php echo'hello</br>'; echo'world!'; ?> output: helllo world! 代...

php正则preg_replace_callback函数用法实例

本文实例讲述了php正则preg_replace_callback函数的用法。分享给大家供大家参考。具体实现方法如下: php正则表达式功能强大,本范例演示了preg_replace_c...