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中preg_match正则匹配中的/u、/i、/s含义

PHP中preg_match正则匹配的/u /i  /s是什么意思 /u 表示按unicode(utf-8)匹配(主要针对多字节比如汉字) /i 表示不区分大小写(如果表达式...

php错误日志简单配置方法

本文实例讲述了php配置错误日志的方法。分享给大家供大家参考,具体如下: php.ini: ; 错误日志 log_errors = On ; 显示错误 display_errors...

php mssql扩展SQL查询中文字段名解决方法

一、问题: 数据库是MS SQLServer2000,要把SQLServer2000里的一张表的数据导入MySQL5,其中SQLServer2000表的字段以简体中文命名(强烈建议不要以...

PHP判断是否有Get参数的方法

可采用如下方式判断 复制代码 代码如下: if(is_array($_GET)&&count($_GET)>0)//判断是否有Get参数 { if(isset($_GET["par...

php数组函数序列之array_pop() - 删除数组中的最后一个元素

array_pop()定义和用法 array_pop() 函数删除数组中的最后一个元素。 语法 array_pop(array)参数 描述 array 必需。规定输入的数组参数。 例子...