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基于session锁防止阻塞请求的方法分析

本文实例讲述了php基于session锁防止阻塞请求的方法。分享给大家供大家参考,具体如下: 说明: 这是一篇参考国外网站http://konrness.com/php5/how-to-...

PHP 常用时间函数资料整理

php常用的时间函数 测试环境:php5.3.29 unix时间戳(从Unix 纪元(January 1 1970 00:00:00 GMT)到给定时间的秒数。)。以下简称时间戳。 返回...

php is_file()和is_dir()用于遍历目录时用法注意事项

1、目录inc有以下内容: 子目录 0 子目录 a footer.html header.html login_function.inc.php mysqli_connect.php s...

使用GROUP BY的时候如何统计记录条数 COUNT(*) DISTINCT

例如这样一个表,我想统计email和passwords都不相同的记录的条数 复制代码 代码如下: CREATE TABLE IF NOT EXISTS `test_users` ( `e...

php求一个网段开始与结束IP地址的方法

本文实例讲述了php求一个网段开始与结束IP地址的方法。分享给大家供大家参考。具体如下: 比如:网段(192168.1.5/24),其子网掩码根据24划分为: 11111111.1111...