Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.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 使用CURL播放Youtube视频_Php_Json_Curl_Oembed - Fatal编程技术网

Php 使用CURL播放Youtube视频

Php 使用CURL播放Youtube视频,php,json,curl,oembed,Php,Json,Curl,Oembed,我使用CURL获取Youtube页面,如下所示: $url = "https://www.youtube.com/watch?v=jyPnQw_Lqds"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $curl_scraped_page = curl_exec($ch); curl_close($ch); echo $curl_scraped_page; $youtube = "http:/

我使用CURL获取Youtube页面,如下所示:

$url = "https://www.youtube.com/watch?v=jyPnQw_Lqds";

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$curl_scraped_page = curl_exec($ch);
curl_close($ch);

echo $curl_scraped_page;
$youtube = "http://www.youtube.com/oembed?url=" . $url. "&format=json";

$curl = curl_init($youtube);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$return = curl_exec($curl);
curl_close($curl);

$result = json_decode($return, true);
echo $result['html'];
视频好像不播放,我不知道为什么。我找到了一个脚本,它通过将数据设置为
format json
,然后将
json
解码为普通
html
来解决这个问题,如下所示:

$url = "https://www.youtube.com/watch?v=jyPnQw_Lqds";

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$curl_scraped_page = curl_exec($ch);
curl_close($ch);

echo $curl_scraped_page;
$youtube = "http://www.youtube.com/oembed?url=" . $url. "&format=json";

$curl = curl_init($youtube);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$return = curl_exec($curl);
curl_close($curl);

$result = json_decode($return, true);
echo $result['html'];
我试图“合并”这两个脚本作为一个功能。我将脚本放在一起,如下所示:

$url = "https://www.youtube.com/watch?v=jyPnQw_Lqds";

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$curl_scraped_page = curl_exec($ch);
curl_close($ch);

echo $curl_scraped_page;
$youtube = "http://www.youtube.com/oembed?url=" . $url. "&format=json";

$curl = curl_init($youtube);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$return = curl_exec($curl);
curl_close($curl);

$result = json_decode($return, true);
echo $result['html'];

正如你看到的顶部的视频不播放。如果您向下滚动到底部,您将看到另一个视频(即JSON回音的视频),实际上可以播放这个视频


如何播放上部(顶部)视频?我在考虑先“查找”这个“对象”,然后将其格式化为json等,但我担心这会把页面搞砸

对我来说,这两个视频都可以播放。我在Ubuntu上使用Chrome。@AgilE这很奇怪……他们在phpFIDLE上玩吗?它不适合我在家里使用所有浏览器和windows 8,也不适合在windows 7上使用…我在本地试用了它,它可以正常工作。但是视频需要很长时间才能显示出来。它最初是一个黑匣子,但随后加载。