php - 使用 preg_match_all 从 html 页面获取 mp3 url
问题描述
我正在尝试从 html 页面中提取 mp3 链接,但我的 preg_match_all 不起作用?
PHP CURL 页面上的 HTML 示例
keyEnabled: true,
remainingDuration: true,
toggleDuration: true,
ready: function (event) {
$(this).jPlayer("setMedia", {
title: "",
mp3: "http://example.com/vod/test.mp3",
});
}
我想得到http://example.com/vod/test.mp3
。
$Pattern = '/((https?:\/\/)?(\w+?\.)+?(\w+?\/)+\w+?.(mp3|ogg))/im';
preg_match_all($Pattern,htmlentities($html),$Matches);
var_dump($Matches);
什么都没有返回,我该怎么做?
示例页面: https ://3v4l.org/G4sLF
解决方案
在您的 URL 中,您有一个-
不包含在\w
http://ns1.indexforce.com/vod/barg-i_sabz_1.mp3
// here __^
使用这个正则表达式:
$Pattern = '~mp3:\h+"((https?://)?\S+\.(mp3|ogg))"~im';
推荐阅读
- scala - 火花选择并添加具有别名的列
- c - 使用宏覆盖静态函数名
- java - Selenium:在字符串中存储时 XPATH 无效
- cloud-foundry - 为什么云代工从 DEA 转移到 diego
- android - 在将数据添加到 recyclerview 时添加(或重新输入)片段时,片段事务滞后
- javascript - 如何使用“$(this)”删除表中的类
- .htaccess - 仅 HTTPS 的 301 问题
- apache - 使用 index.php 将 htaccess 旧文件夹重定向到新文件夹
- haskell - 不确定如何使用给定的数据类型
- java - 将 Spark SQL 与 Spark 流结合使用