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防注入代码

介绍两种方法吧,首先请把以下代码保存为safe.php放在网站根目录下,然后在每个php文件前加include(“/safe.php“);即可 : php防注入代码方法一: 复制代码 代...

php中使用explode查找某个字符是否存在的方法

这个方法同样可以用于判断是否有该分隔符号。例如: 复制代码 代码如下: <?php if($_MODULE[tg1_tjly]){ $tg1_tjly = explode("|",...

php实现映射操作实例详解

php实现映射操作实例详解

本文实例讲述了php实现映射操作。分享给大家供大家参考,具体如下: 映射 映射,或者射影,在数学及相关的领域经常等同于函数。基于此,部分映射就相当于部分函数,而完全映射相当于完全函数。...

php版阿里云OSS图片上传类详解

本文实例讲述了php版阿里云OSS图片上传类。分享给大家供大家参考,具体如下: 1.阿里云基本函数 /** * 把本地变量的内容到文件 * 简单上传,上传指定变量的内存值作为ob...

php和js交互一例-PHP教程,PHP应用

复制代码 代码如下:<html>  <head>  <meta http-equiv="Content-Type" ...