PHP实现通过正则表达式替换回调的内容标签

作者:小卒过河 时间:2024-05-13 09:25:39 

本文实例讲述了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,正则,替换
0
投稿

猜你喜欢

  • Go语言net包RPC远程调用三种方式http与json-rpc及tcp

    2024-05-29 22:06:14
  • python中使用正则表达式的连接符示例代码

    2021-07-08 09:34:43
  • 几个关于python Pdf 技巧的分享

    2021-11-30 11:39:58
  • python中sleep函数用法实例分析

    2023-10-19 15:33:24
  • 网站508规范(译)

    2008-04-03 13:26:00
  • Python Pandas聚合函数的应用示例

    2022-12-13 22:39:31
  • javascript实现延时显示提示框效果

    2024-04-25 13:10:42
  • uni-app自定义导航栏右侧做增加按钮并跳转链接功能

    2024-04-18 10:52:29
  • mysql 5.7.17 winx64解压版安装配置方法图文教程

    2024-01-22 07:47:16
  • 图像替换新技术:状态域方法[译]

    2009-08-06 16:41:00
  • asp+XMLHTTP的国际域名查询系统(whois)源代码

    2008-02-16 09:23:00
  • pytorch finetuning 自己的图片进行训练操作

    2023-03-17 00:46:53
  • 用python实现海龟赛跑小游戏

    2023-03-14 22:59:39
  • python SocketServer源码深入解读

    2023-04-15 18:38:44
  • 通过百度地图获取公交线路的站点坐标的js代码

    2024-04-18 09:28:14
  • Python执行Linux系统命令的4种方法

    2023-08-10 19:04:50
  • 详解php中implode explode serialize json msgpack性能对比

    2023-09-03 18:00:19
  • ASP CacheControl 属性

    2009-04-28 13:09:00
  • 利用Python实现自动化监控文件夹完成服务部署

    2023-03-15 00:02:04
  • python爬取网易云音乐排行榜实例代码

    2023-07-24 09:26:52
  • asp之家 网络编程 m.aspxhome.com