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程序设计有所帮助。

相关文章

Linux php 中文乱码的快速解决方法

在ubuntu下php网页输出乱码,在不涉及数据库编码的情况下: 修改“/etc/php5/apache2/php.ini”将 default_charset = "iso-8859-1...

php实现根据词频生成tag云的方法

本文实例讲述了php实现根据词频生成tag云的方法。分享给大家供大家参考。具体如下: 这里给定一段文本,分析文本的词频分布,生成tag云 <?php /** * Ta...

php带抄送和密件抄送的邮件发送方法

本文实例讲述了php带抄送和密件抄送的邮件发送方法。分享给大家供大家参考。具体分析如下: 程序中用到了php的mail函数,该函数定义如下: bool mail ( string $t...

php树型类实例

本文实例讲述了php树型类。分享给大家供大家参考。具体分析如下: 该实例原理简单,学过数据结构的一看就明白是什么道理了,不过今天在使用时数据中出现了子节点id(71)小于父节点id(10...

php实现随机生成易于记忆的密码

本文实例讲述了php实现随机生成易于记忆的密码。分享给大家供大家参考。具体实现方法如下: 这里通过预定义一些单词,让php随机从这些单词中选择进行组合生成密码 function ra...