存储在变量中的回声图像



现在整天都被困在这件事上。我使用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;  

如果答案再次出现,我将接受

谢谢大家

尝试这个,

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>");  

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>");

相关内容

  • 没有找到相关文章

最新更新