Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何获取jwplayer的URL源代码部分_Php_Html_Regex_Jwplayer - Fatal编程技术网

Php 如何获取jwplayer的URL源代码部分

Php 如何获取jwplayer的URL源代码部分,php,html,regex,jwplayer,Php,Html,Regex,Jwplayer,你好,朋友们 如何获取jwplayer的URL源代码部分,我指的是mp4部分,我在这里找到了我要查找的内容 我试着使用它,但我做不好,抱歉我的英语不好,有人能看看我下面的php代码吗…我想在viral022018.html中获取链接或其中的所有mp4 URL <!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=d

你好,朋友们

如何获取jwplayer的URL源代码部分,我指的是mp4部分,我在这里找到了我要查找的内容

我试着使用它,但我做不好,抱歉我的英语不好,有人能看看我下面的php代码吗…我想在viral022018.html中获取链接或其中的所有mp4 URL

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<link href='https://fonts.googleapis.com/css?family=Hanuman' rel='stylesheet' type='text/css'>
<link href="https://fonts.googleapis.com/css?family=Scada" rel="stylesheet">
<link href="jwplayer-7.12.8/skins/prime.min2.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="jwplayer-7.12.8/jwplayer.js"></script>
<script type="text/javascript">jwplayer.key="I9HOJrL1NmqruQ60as34wt34/23422dsdrwer==";</script>
</head>
<body>
<div id="picasa" class="picasa"></div>
<script type="text/javascript">
    var playerInstance = jwplayer("picasa");
        playerInstance.setup({
        id:'picasa',
        controls: true,
        displaytitle: true,

        flashplayer: "//ssl.p.jwpcdn.com/player/v/7.12.5/jwplayer.flash.swf",
        width: "100%",
        height: "100%",
        aspectratio: "16:9",
        fullscreen: "true",
        provider: 'http',
        autostart: false,
        image:'http://localhost/viral/viralvideo.jpg',
            sources: [{file:"http://localhost/srt/43534234/viral022018SD.MP4",label:"SD",type: "video/mp4"},{file:"http://localhost/srt/43534234/viral022018HD.MP4",label:"HD",type: "video/mp4",default: true}],
            sharing:{
                link: "",
                code: "",
                heading: "Share",
                sites: ["facebook","twitter","tumblr","googleplus","reddit","linkedin","interest","email"],
            },
sharing:{
                link: "",
                code: "",
                heading: "Share",
                sites: ["facebook","twitter","tumblr","googleplus","reddit","linkedin","interest","email"],
            },
tracks: [{
            file: 'http://localhost/srt/viralvideo022018.srt',
            label: 'English',
            kind: 'captions',
            "default":true
}],

     captions: {
        color: '#FFEB3B',
        fontSize: 14,
        fontFamily: 'Scada, Hanuman, sans-serif, Verdana, cursive',
        fontOpacity: 100,
        backgroundOpacity: 0,
backgroundColor: '#000000',
        edgeStyle: 'raised',
        windowColor: '#000000',
        windowOpacity: 0
    },
skin: {
        name: 'prime',
    },




          });

</script>
</body>
</html>
谢谢,希望有人能帮我…谢谢

这是我的php代码

<?php
$html = file_get_contents('https://localhost/video/viral022018.html');
//$dom->loadHtml('', LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
$dom = new DOMDocument();
$dom->loadHTML($html);

$xpath = new DOMXPath($dom);

$sources = [];
foreach ($xpath->query("//script[@type=\"text/javascript\"]") as $script) {
    if (stristr($script->nodeValue, 'playerInstance') !== false) {
        preg_match_all('#file: \"(.+)\"#', $script->nodeValue, $match);
        $sources = $match[1];
    }
}

print_r($sources);
?>
这是viral022018.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<link href='https://fonts.googleapis.com/css?family=Hanuman' rel='stylesheet' type='text/css'>
<link href="https://fonts.googleapis.com/css?family=Scada" rel="stylesheet">
<link href="jwplayer-7.12.8/skins/prime.min2.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="jwplayer-7.12.8/jwplayer.js"></script>
<script type="text/javascript">jwplayer.key="I9HOJrL1NmqruQ60as34wt34/23422dsdrwer==";</script>
</head>
<body>
<div id="picasa" class="picasa"></div>
<script type="text/javascript">
    var playerInstance = jwplayer("picasa");
        playerInstance.setup({
        id:'picasa',
        controls: true,
        displaytitle: true,

        flashplayer: "//ssl.p.jwpcdn.com/player/v/7.12.5/jwplayer.flash.swf",
        width: "100%",
        height: "100%",
        aspectratio: "16:9",
        fullscreen: "true",
        provider: 'http',
        autostart: false,
        image:'http://localhost/viral/viralvideo.jpg',
            sources: [{file:"http://localhost/srt/43534234/viral022018SD.MP4",label:"SD",type: "video/mp4"},{file:"http://localhost/srt/43534234/viral022018HD.MP4",label:"HD",type: "video/mp4",default: true}],
            sharing:{
                link: "",
                code: "",
                heading: "Share",
                sites: ["facebook","twitter","tumblr","googleplus","reddit","linkedin","interest","email"],
            },
sharing:{
                link: "",
                code: "",
                heading: "Share",
                sites: ["facebook","twitter","tumblr","googleplus","reddit","linkedin","interest","email"],
            },
tracks: [{
            file: 'http://localhost/srt/viralvideo022018.srt',
            label: 'English',
            kind: 'captions',
            "default":true
}],

     captions: {
        color: '#FFEB3B',
        fontSize: 14,
        fontFamily: 'Scada, Hanuman, sans-serif, Verdana, cursive',
        fontOpacity: 100,
        backgroundOpacity: 0,
backgroundColor: '#000000',
        edgeStyle: 'raised',
        windowColor: '#000000',
        windowOpacity: 0
    },
skin: {
        name: 'prime',
    },




          });

</script>
</body>
</html>
请尝试此正则表达式:

{\s*file\s*:\s*["']\s*(http[^"']+\.mp4)
在这里尝试一下:

匹配的URL位于组1中

编辑:添加\.mp4以使其特定于这些文件

编辑:要在PHP中实现,您可以执行以下操作:

preg_match_all('/{\s*file\s*:\s*["\']\s*(http[^"\']+\.mp4)/i', $subject,
    $result, PREG_PATTERN_ORDER);
$result = $result[1];

$result将是由正则表达式中编号组1匹配的所有文本组成的数组。但是我把它留给您,让您在上面的代码中插入更改变量名称以匹配所需的内容。

谢谢您的更正。它已经更新了…有人帮我解决这个问题…我编辑了我的答案,以提供一种在PHP中实现正则表达式的通用方法,您可以根据代码的具体情况进行调整。希望能有帮助。是的,你提供的链接和代码可以正常工作,但当它出现在我的本地服务器上时,就不能正常工作了,…我仍然希望使用文件\u gets\u内容到这个URL我将您的代码实现到我的php代码中,但它不起作用..如果您可以使用上面的示例php代码并实现您的正则表达式代码,是否可以..我再次尝试使用带有链接的文件\u gets\u内容,但没有显示$re='/{\sfile\s:\s*[\']\s*http[^\']+\.mp4/mi“;$str=file_get_contents”;$preg_match_all$re,$str,$matches,preg_SET_ORDER,0;//打印整个匹配结果var_dump$matches;我不太熟悉您在PHP中使用的方法,但在我看来,您使用了两种相互冲突的方法。一方面,您使用XPath解析DOM,另一方面,您使用的是我们使用正则表达式从HTML中获取原始数据。我认为您需要这样做或那样做。为什么不尝试直接在$HTML变量上运行我的代码。如果$HTML变量在viral022018.HTML中包含HTML,正如您在上面粘贴的那样,则正则表达式应该只获取两个匹配项并将它们作为数组存储在$result中。您可能过于复杂了使用不必要的XPath修改代码。。。