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 $_FILES函数详解

如: 复制代码 代码如下: <form enctype="multipart/form-data" action="upload.php" method="post"> &l...

php中的一个中文字符串截取函数

PHP代码: -------------------------------------------------------------------------------- <?...

PHP如何读取由JavaScript设置的Cookie

cookie在开发中使用的非常多,但如果是使用JavaScript设置cookie然后使用PHP读取出来如何实现呢?即PHP与JavaScript下Cookie的交互使用是否可行呢?...

php实现的Cookies操作类实例

本文实例讲述了PHP实现的Cookies操作类及其用法,分享给大家供大家参考。具体分析如下: 一、功能: 1.保存,读取,更新,清除cookies数据。 2.可设置前缀。 3.强制超时控...

PHP实现约瑟夫环问题的方法分析

本文实例讲述了PHP实现约瑟夫环问题的方法。分享给大家供大家参考,具体如下: 一、概述 先来看看网上比较常见的约瑟夫环问题描述:约瑟夫环(约瑟夫问题)是一个数学的应用问题:已知n个人(以...