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中的字符串编码转换(自动识别原编码)

复制代码 代码如下:/** * 对数据进行编码转换 * @param array/string $data     ...

效率较高的php下读取文本文件的代码 原创

 fread :以字节位计算长度,按照指定的长度和次数读取数据,遇到结尾或完成指定长度读取后停止.  fgets :整行读取,遇到回车换行或结尾停...

PHP实现对数组简单求交集,差集,并集功能示例

PHP实现对数组简单求交集,差集,并集功能示例

本文实例讲述了PHP实现对数组简单求交集,差集,并集功能。分享给大家供大家参考,具体如下: <?php $arr1 = array( '0' => 'zero',...

PHP删除特定数组内容并且重建数组索引的方法.

复制代码 代码如下: $a = array('a','b','c','d'); unset($a[2]); print_r($a); 但是这种方法的最大缺点是没有重建数组索引. 经过查资...

php地址引用(php地址引用的效率问题)

复制代码 代码如下: <?php echo 'begin time:'.$begin=microtime(false).'<br/>';//begin to count...