0
我使用YouTube API搜索视频。我的问题是,完成搜索时,从搜索的输出是从YouTube的api输出中删除videoid
video_name video_id
我只是想让它显示
video_name
继承人我的代码来显示搜索结果
$client = new Google_Client();
$client->setDeveloperKey($DEVELOPER_KEY);
$youtube = new Google_Service_YouTube($client);
try {
$searchResponse = $youtube->search->listSearch('id,snippet', array(
'q' => $_GET['q'],
'maxResults' => $_GET['maxResults'],
));
$videos = '';
$channels = '';
$playlists = '';
// Add each result to the appropriate list, and then display the lists of
// matching videos, channels, and playlists.
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;
您能举一个实际输出的例子吗? – Timmy
迈克尔·杰克逊 - 镜中之人(原始剪辑)(F9Nh84lfvW0观看此视频) 如果我想输出是 迈克尔·杰克逊 - 镜中之人(原始剪辑)(观看此视频) –
我不太熟悉'sprintf',但你想删除'$ searchResult ['id'] ['videoId']'而不会破坏你的代码。我建议将它包装在特定的字符串之间,例如'vidid [“。$ searchResult ['id'] ['videoId']。”]',然后删除'vidid ['和']'之间的所有内容。可能不是最好的办法,但它:p – Timmy