如何使用php获取流媒体的内容

如何使用php获取流媒体的内容,php,Php,如何使用php获取流媒体的内容 例: 我试图获取内容,但却丢失了很多数据 如何读取整个文件,从上面的URL返回所有数据 function curlGet($URL) { if ($stream = fopen($URL, 'r')) { echo '<pre>'; echo urldecode(urldecode(urldecode(stream_get_contents($stream)))); fclose($stream); echo

如何使用php获取流媒体的内容

例:

我试图获取内容,但却丢失了很多数据

如何读取整个文件,从上面的URL返回所有数据

function curlGet($URL) {
 if ($stream = fopen($URL, 'r')) {
    echo '<pre>';
        echo urldecode(urldecode(urldecode(stream_get_contents($stream))));
    fclose($stream);
    echo '</pre>';
    }
}  

echo curlGet('http://www.youtube.com/get_video_info?&video_id=Wd9WOxJXQq4');
函数curlGet($URL){
如果($stream=fopen($URL,'r')){
回声';
echo urldecode(urldecode(urldecode(stream_get_contents($stream)));
fclose($流);
回声';
}
}  
回声卷发器http://www.youtube.com/get_video_info?&video_id=Wd9WOxJXQq4');

为什么要进行三重解码

您显示的URL不是流,而是纯文本

使用更易于处理的JSON API:

http://gdata.youtube.com/feeds/api/videos/Wd9WOxJXQq4?v=2&alt=json
function curlGet($URL) {
 if ($stream = fopen($URL, 'r')) {
    echo '<pre>';
        echo urldecode(urldecode(urldecode(stream_get_contents($stream))));
    fclose($stream);
    echo '</pre>';
    }
}  

echo curlGet('http://www.youtube.com/get_video_info?&video_id=Wd9WOxJXQq4');
http://gdata.youtube.com/feeds/api/videos/Wd9WOxJXQq4?v=2&alt=json

<?php
$json = json_decode(trim(file_get_contents(
    'http://gdata.youtube.com/feeds/api/videos/Wd9WOxJXQq4?v=2&alt=json'
)));

print_r($json);