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 /** * @author xiaoxiao <x_824@sina.com> 2011-1-12 * @link http://xiaoyaoxia.cn...

php实现curl模拟ftp上传的方法

本文实例讲述了php实现curl模拟ftp上传的方法。分享给大家供大家参考。具体如下: <?php function upload($dir,$src,$dest) {...

php array_chunk()函数用法与注意事项

本文实例讲述了php array_chunk()函数用法与注意事项。分享给大家供大家参考,具体如下: 定义和用法 array_chunk() 函数把数组分割为新的数组块。 其中每个数组的...

PHP版 汉字转码的实现详解

如下所示:复制代码 代码如下:<?phpfunction unicode_encode($str, $encoding='GBK', $prefix='&#', $postfix=...

微信公众平台消息接口校验与消息接口响应实例

本文实例讲述了微信公众平台消息接口校验与消息接口响应的方法。分享给大家供大家参考。具体分析如下: 开发微信公众平台消息接口过程中,我们首先需要验证消息接口的有效性,验证通过后,才可以进行...