使用preg_match_all从html页面获取mp3网址

时间:2019-01-21 15:19:46

标签: php regex

我正在尝试从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

1 个答案:

答案 0 :(得分:4)

在您的网址中,import UIKit class PlayCardView: UIView { override init(frame: CGRect) { super.init(frame: frame) backgroundColor = UIColor.red } required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) backgroundColor = UIColor.red } } class SingleTapGestureForMultiView: UIViewController { var viewArray: [UIView]! var scrollView: UIScrollView! override func viewDidLoad() { super.viewDidLoad() scrollView = UIScrollView(frame: UIScreen.main.bounds) view.addSubview(scrollView) let tapGesture = UITapGestureRecognizer(target: self, action: #selector(tapGetsure(_:))) scrollView.addGestureRecognizer(tapGesture) addSubviews() } func addSubviews() { var subView: PlayCardView let width = UIScreen.main.bounds.width; let height = UIScreen.main.bounds.height; let spacing: CGFloat = 8.0 let noOfViewsInARow = 3 let viewWidth = (width - (CGFloat(noOfViewsInARow+1) * spacing))/CGFloat(noOfViewsInARow) let viewHeight = (height - (CGFloat(noOfViewsInARow+1) * spacing))/CGFloat(noOfViewsInARow) var yCordinate = spacing var xCordinate = spacing for index in 0..<20 { subView = PlayCardView(frame: CGRect(x: xCordinate, y: yCordinate, width: viewWidth, height: viewHeight)) subView.tag = index xCordinate += viewWidth + spacing if xCordinate > width { xCordinate = spacing yCordinate += viewHeight + spacing } scrollView.addSubview(subView) } scrollView.contentSize = CGSize(width: width, height: yCordinate) } @objc func tapGetsure(_ gesture: UITapGestureRecognizer) { let location = gesture.location(in: scrollView) print("location = \(location)") var locationInView = CGPoint.zero let subViews = scrollView.subviews for subView in subViews { //check if it subclass of PlayCardView locationInView = subView.convert(location, from: scrollView) if subView.isKind(of: PlayCardView.self) { if subView.point(inside: locationInView, with: nil) { // this view contains that point print("Subview at \(subView.tag) tapped"); break; } } } } } 中没有包含破折号-

\w

使用此正则表达式:

http://ns1.indexforce.com/vod/barg-i_sabz_1.mp3
//                         here __^