Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.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 Youtube从live_流获取视频id_Php_Youtube - Fatal编程技术网

php Youtube从live_流获取视频id

php Youtube从live_流获取视频id,php,youtube,Php,Youtube,YouTube如何使用php从live_流中获取视频id。我正在使用这个url https://www.youtube.com/embed/live_stream?channel=UCmyKnNRH0wH-r8I-ceP-dsg 我尝试了这段代码,但没有返回任何内容 function getvideourl($chid){ $videoId = null; // Fetch the livestream page if($data = file_get_contents('https://

YouTube如何使用php从live_流中获取视频id。我正在使用这个url

 https://www.youtube.com/embed/live_stream?channel=UCmyKnNRH0wH-r8I-ceP-dsg
我尝试了这段代码,但没有返回任何内容

function getvideourl($chid){
$videoId = null;

// Fetch the livestream page
if($data = file_get_contents('https://www.youtube.com/embed/live_stream?channel='.$chid))
{
    // Find the video ID in there
    if(preg_match("#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=v\/)[^&\n]+(?=\?)|(?<=v=)[^&\n]+|(?<=youtu.be/)[^&\n]+#", $link, $matches))
        $videoId = $matches[1];
    
    else
        $videoId ="";
}
else
    throw new Exception('Couldn\'t fetch data');

 $video_url = "https://www.youtube.com/embed/".$videoId;


return $video_url;
}
函数getvideourl($chid){ $videoId=null; //获取livestream页面 如果($data=file\u get\u contents($https://www.youtube.com/embed/live_stream?channel=“($chid)) { //在那里找到视频ID
如果(preg_match(“#)(?您使用的是变量
$link
而不是
$data
,请尝试如下更改:

if(preg_match("#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=v\/)[^&\n]+(?=\?)|(?<=v=)[^&\n]+|(?<=youtu.be/)[^&\n]+#", $data, $matches))
        $videoId = substr($matches[0], 0, -2);
if(preg#u match(“#”)要简单得多。