Answer the question
In order to leave comments, you need to log in
How to add PHP code?
There is a site go2s.ru on it videos speared from YouTube. I want the video to open on a new page when you click on the link, and not like now.
The following function is responsible for parsing:
function get_youtube_video($key) {
$DEVELOPER_KEY = 'AIzaSyAgk6lKh5IKBDdH_fgBlVcT2hEsmAY5jQ8';
$client = new Google_Client();
$client->setDeveloperKey($DEVELOPER_KEY);
// Define an object that will be used to make all API requests.
$youtube = new Google_Service_YouTube($client);
// Call the search.list method to retrieve results matching the specified
// query term.
$searchResponse = $youtube->search->listSearch('id,snippet', array(
'q' => $key,
'maxResults' => 50,
));
$videos = '';
$channels = '';
$playlists = '';
/*
echo '<pre>';
var_dump($searchResponse['items']);
echo '</pre>';
*/
echo '<div>';
foreach($searchResponse['items'] as $searchResult) {
switch ($searchResult['id']['kind']) {
case 'youtube#video':
$videoId=$searchResult['id']['videoId'];
$title=$searchResult['snippet']['title'];
$desc=$searchResult['snippet']['description'];
$img = 'https://i.ytimg.com/vi/'.$videoId.'/mqdefault.jpg'; // [0, 1, 2, 3, default, mqdefault, hqdefault, maxresdefault] http://shpargalkablog.ru/2013/06/youtube.html
$a1='<a href="http://www.youtube.com/embed/'.$videoId.'?autoplay=1&autohide=1&border=0&egm=0&showinfo=0" class="lightview" data-lightview-type="iframe" data-lightview-options="width: 638,height: 360">';
$a2='</a>';
echo '<div class="video">';
echo $a1.'<img style="float: left; margin: 15px;" src="'.$img.'" title="'.$title.'" alt="'.$title.'">'.$a2;
echo $a1.$title.$a2.'<br>';
echo $desc.'<br>';
echo '</div>';
echo '<div style="clear: both"></div>';
}
}
echo '</div>';
}
Answer the question
In order to leave comments, you need to log in
If you mean a new tab, then you are coming from the wrong side, this is client logic, not server logic. For example, you can add target="_blank" to the link.
$a1='<a href="http://www.youtube.com/embed/'.$videoId.'?autoplay=1&autohide=1&border=0&egm=0&showinfo=0" class="lightview" data-lightview-type="iframe" data-lightview-options="width: 638,height: 360" target="_blank">';
<a href="http://www.youtube.com/embed/
replace
<a target="_blank" href="http://www.youtube.com/embed/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question