如何使用 php 中的 file_get_contents 获取视频 url

How to get video url using file_get_contents in php

我正在尝试从其他站点获取视频和海报 让我们称之为 othersite.com

其他site.com有这个参数:

<div class="player">
    <div id="l_player" class='l-player' >
        <noscript>
            <video style="width:100%; height:100%;"
               controls="controls"
               autobuffer="autobuffer"
               class="player-html5"
               preload="metadata"
               poster="http://othersite.com/img.jpg">
                <source src="http://othersite.com/video.mp4" type="video/mp4">
            </video>
        </noscript>
    </div>  

使用下面的 php 我从 opengraph 标签中获取了图像,但我正在尝试获取我无法获取的 mp4 url

$Agent  = array('http' => array('user_agent' => 'Mozilla/5.0 (Linux; U; Android 4.0; en-us; GT-I9300 Build/IMM76D)'));
$String = file_get_contents('http://www.othersite.com/'. $video .'/', false, stream_context_create($Agent) );
preg_match("/<source src=\"(.*)\" controls type=\"video\/mp4\"/", $String, $VideoURL);
$VideoURL = $VideoURL[1];
$IMG = getstring($String,'<meta property="og:image" content="','"');

我的 php 正在获取图像,你知道我在 preg_match 中做错了什么以及如何获取 http://othersite.com/video.mp4

这可以通过以下方式使用 Preg_Match 来完成。它非常简单,而且效果非常好!

$source = file_get_contents("That Page");

preg_match("'<source src=\"(.*?)\" type=\"video/mp4\">'si", $source, $match);
if($match) echo "result=".$match[1];

这应该可以满足您的要求。

在最近的评论之后,我觉得我还应该补充一点 si 修饰符使这个正则表达式更宽松。