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