I'm trying to fetch YouTube thumbnails and video id's using the API v3 and echo them into HTML, however I need to echo two variables at the same time. At the moment I have the following:
<?php
$url = 'https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=12&playlistId=UUDWdi7vjr3ac_z_VMMeiL_Q&key=*************************';
$data = file_get_contents($url);
if ((preg_match_all("/\"videoId\":\s*\"(.+)\"/", $data, $video_get) ) && (preg_match_all("/\"title\":\s*\"(.+)\"/", $data, $title_get) ) ) {
foreach (($video_get[1] as $videoid) && foreach ($title_get[1] as $title ) ){
echo ("<div id=\"video-thumb\" class=\"col-sm-6\"><img id=\"video-thumb-320180\" src=\"https://i.ytimg.com/vi/'.$videoid.'/mqdefault.jpg\"><div class=\"video-hover\"><img class=\"play-hover\" src=\"images/play.png\"></div><h2 class=\"video-title\"><i><a href=\"https://youtube.com/watch?v='.$videoid.'\">'.$title.'</a></h2></i></div>");
}
}
else {
echo ("Error fetching uploads!")
}
?>
However after trying this it seems I cannot use foreach as && foreach as. What's the solution here?
file_get_contents()output.preg_matchanything. Just usejson_decode().