php Youtube从live_流获取视频id
YouTube如何使用php从live_流中获取视频id。我正在使用这个urlphp 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://
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(“#”)要简单得多。