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版微信小店接口开发方法。分享给大家供大家参考,具体如下: 首先 大家可以去下一份小店开发的 API接口 因为 下面所有的 微信小店接口 数据格式 参数 API手册 里...

PHP音乐采集(部分代码)

<?PHP set_time_limit(0); mysql_connect("localhost","root",""); mysql_select_Db("music_36g"...

PHP利用APC模块实现文件上传进度条的方法

本文实例讲述了PHP利用APC模块实现文件上传进度条的方法。分享给大家供大家参考。具体分析如下: 以前的php5.2之前的版本是不能可使用APC模块的,因为之前的压根就没有这个APC模块...

php 解决扫描二维码下载跳转问题

php 解决扫描二维码下载跳转问题 首先我们指定一个url,比如 http://it.lovepet.vip 用这个地址生成二维码,二维码的生成方式有很多种,到网上搜搜就知道。 我们可...

php版本的cron定时任务执行器使用实例

本文实例讲述了php版本的cron定时任务执行器使用方法,是非常实用的一个功能应用。具体方法如下: 由于服务器crontab只能精确到分钟,因此程序的起点也是分钟。 该功能一共包括三个部...