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性能分析工具xhprof的安装使用与注意事项

前言 xhprof由facebook开源出来的一个PHP性能监控工具,占用资源很少,甚至能够在生产环境中进行部署。 它可以结合graphviz使用,能够以图片的形式很直观的展示代码执行...

drupal 代码实现URL重写

以下是实现例子: 复制代码 代码如下: /* * 伪地址转原地址 (url_alter) */ function example_url_inbound_alter(&$path, $o...

php中\r \r\n \t的区别示例介绍

\n 软回车: 在Windows 中表示换行且回到下一行的最开始位置。相当于Mac OS 里的 \r 的效果。 在Linux、unix 中只表示换行,但不会回到下一行的开始位置。 \r...

ezSQL PHP数据库操作类库

ezSQL 下载地址: 下载 : ezSQL 新版本是2.05添加了很多支持,包括 CodeIgniter,MSSQL, PDO 等等 我之前也为 CodeIgniter 写过一次,不过...

php动态变量定义及使用

本文实例讲述了php动态变量定义及使用方法。分享给大家供大家参考。具体如下: <?php $var_name = "ic"; //定义变量$var_name $$v...