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 setcookie指定domain参数后,在IE下设置cookie失效的解决方法

下面的代码:在chrome和firefox下可以生成三个cookie: cookie[one]、cookie[two]、cookie[three] 在IE下,只能生成cookie[one...

谈谈PHP的输入输出流

今天有人再PHPCHINA上问我关于PHP传XML怎么做?,再上面已经给出了相应的解决方法。顺便谈谈PHP的输入输出流。    今天暑假在公司的时候,恰好同...

网页上facebook分享功能具体实现

复制代码 代码如下: <span style=" font-family: Verdana, Arial, Helvetica, sans-serif; word-wrap: no...

PHP采用curl模仿用户登陆新浪微博发微博的方法

本文实例讲述了PHP采用curl模仿用户登陆新浪微博发微博的方法。分享给大家供大家参考。具体实现方法如下: 现在用php做模仿用户登录我们都会使用到PHP curl函数了,因为只有它才可...

详解phpmyadmin相关配置与错误解决

详解phpmyadmin相关配置与错误解决 缺少mcrypt扩展 sudo apt-get install php5-mcrypt sudo php5enmod mcrypt 检查:...