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实现懒加载的方法

本文实例讲述了PHP实现懒加载的方法。分享给大家供大家参考。具体分析如下: 寻常php的加载是通过include(),require()等方法来加载外部文件,之后再通过实例调用方法或直接...

PHP的加密方式及原理

复制代码 代码如下: <?php //变量注意区分数字 "0" 和 字符"O" $OOO000000=urldecode('%66%67%36%73%62%65%68%70%72%...

PHP中empty,isset,is_null用法和区别

1.empty用法 bool empty ( mixed var) 如果 var 是非空或非零的值,则 empty() 返回 FALSE。换句话说,""、0、"0"、NULL、FALS...

PHP中判断文件存在使用is_file还是file_exists?

判断文件存在用is_file还是file_exists? 在写程序时发现在判断文件是否存在时,有两种写法,有的人用了is_file,有的人用了file_exists,用哪个更好或者说更合...

PHP自带函数给数字或字符串自动补齐位数

先来看个例子:需求为生成4位数,不足前面补0 <?php //生成4位数,不足前面补0 $var=sprintf("%04d", 2); echo $var;/...