我整天都被困在这一天。我正在使用youtube API制作脚本。我试图显示youtube缩略图。我可以在代码的末尾以简单的html和php回显图像,但是我在这部分回应时遇到了问题。
在我发布代码之前,我将缩略图存储在变量
中$imgsrc="<img src=http://img.youtube.com/vi/".$searchResult['id'] ['videoId']."/hqdefault.jpg height=125 width=125>";
和我试图回应的代码
// Add each result to the appropriate list, and then display the lists of
// matching videos, channels, and playlists.
foreach ($searchResponse['items'] as $searchResult) {
switch ($searchResult['id']['kind']) {
case 'youtube#video':
$videos .= sprintf('<li><img src="'.$imgsrc.'">; %s (%s)</li>', $searchResult['snippet']['title'],
$searchResult['id']['videoId']."<a href=/video.php?".$searchResult['id']['videoId']." target=_blank> Watch This Video</a>");
break;
case 'youtube#channel':
$channels .= sprintf('<li>%s (%s)</li>',
$searchResult['snippet']['title'], $searchResult['id']['channelId']);
break;
case 'youtube#playlist':
$playlists .= sprintf('<li>%s (%s)</li>',
$searchResult['snippet']['title'], $searchResult['id']['playlistId']);
break;
}
}
任何帮助都会被大大提升
一个鞋底发布了答案,然后删除了他的答案,这就是所需要的:
foreach ($searchResponse['items'] as $searchResult) {
$imgsrc="<img src=http://img.youtube.com/vi/".$searchResult['id']
['videoId']."/hqdefault.jpg height=125 width=125>";
switch ($searchResult['id']['kind']) {
case 'youtube#video':
$videos .= sprintf('<li>'.$imgsrc.'; %s (%s)</li>', $searchResult['snippet']['title'],
$searchResult['id']['videoId']."<a href=/video.php?".$searchResult['id']['videoId']." target=_blank> Watch This Video</a>");
break;
如果答案再次出现,我会接受
谢谢你们
答案 0 :(得分:0)
试试这个,
foreach ($searchResponse['items'] as $searchResult) {
$imgsrc = "<img src='http://img.youtube.com/vi/".$searchResult['id']['videoId']."/hqdefault.jpg' height='125' width='125'>";
$videos .= sprintf('<li>%s %s (%s)</li>', $imgsrc , $searchResult['snippet']['title'],
$searchResult['id']['videoId']."<a href=/video.php?".$searchResult['id']['videoId']." target=_blank> Watch This Video</a>");
OR
foreach ($searchResponse['items'] as $searchResult) {
$imgsrc="http://img.youtube.com/vi/".$searchResult['id']['videoId']."/hqdefault.jpg";
$videos .= sprintf('<li>'.$imgsrc.' %s (%s)</li>', $searchResult['snippet']['title'],
$searchResult['id']['videoId']."<a href=/video.php?".$searchResult['id']['videoId']." target=_blank> Watch This Video</a>");