Alex Emile
Alex Emile

Reputation: 15

remove videoid from youtube api output

Im using the youtube api to search for videos. My issue is that when a search is completed, the output from the search is

video_name  video_id

I just want it to show

video_name

heres my code to display search results

 $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;  

Upvotes: 0

Views: 112

Answers (1)

PsychoMantis
PsychoMantis

Reputation: 1015

I'm not too familiar with sprintf but you want to remove

$searchResult['id']['videoId']

without breaking your code.

I'd suggest wrapping it in between a particular string e.g.

vidid[".$searchResult['id']['videoId']."]

and then remove all content between vidid[ and ].

Upvotes: 1

Related Questions