[opgelost] $_GET hulp
Het lukt mij niet om dit scriptje aan de praat te krijgen:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
$_GET['playlist'];
$id = array ('minecraft'=>'B96604659AE908B9', enz.);
if(empty($_GET)) {
echo "selecteer een playlist";
}
else {
print_r($_GET);
//Playlist: PLB96604659AE908B9, remove PL from name
$url = "https://gdata.youtube.com/feeds/api/playlists/".$playlist_id."?v=2&alt=json";
$data = json_decode(file_get_contents($url),true);
$info = $data["feed"];
$video = $info["entry"];
$nVideo = count($video);
echo "Let's play".$info["title"]['$t'].'<br/><hr><br/>';
for($i=0;$i<9;$i++){
echo "<div class=\"playlist-video\"><a href='".$video[$i]['link'][0]['href']."'><img style='width: 100%; ' src='".$video[$i]['media$group']['media$thumbnail'][1]['url']."' /></a><br />";
echo "Name: ".$video[$i]['title']['$t'].'<br/><hr><div>';
}
}
?>
$_GET['playlist'];
$id = array ('minecraft'=>'B96604659AE908B9', enz.);
if(empty($_GET)) {
echo "selecteer een playlist";
}
else {
print_r($_GET);
//Playlist: PLB96604659AE908B9, remove PL from name
$url = "https://gdata.youtube.com/feeds/api/playlists/".$playlist_id."?v=2&alt=json";
$data = json_decode(file_get_contents($url),true);
$info = $data["feed"];
$video = $info["entry"];
$nVideo = count($video);
echo "Let's play".$info["title"]['$t'].'<br/><hr><br/>';
for($i=0;$i<9;$i++){
echo "<div class=\"playlist-video\"><a href='".$video[$i]['link'][0]['href']."'><img style='width: 100%; ' src='".$video[$i]['media$group']['media$thumbnail'][1]['url']."' /></a><br />";
echo "Name: ".$video[$i]['title']['$t'].'<br/><hr><div>';
}
}
?>
Ik wil dat ik een link in voer: playlist.php?playlist=minecraft.
Dan moet hij de code weergeven: B96604659AE908B9
Wie kan me helpen?
alvast bedankt!
Gewijzigd op 15/05/2013 22:31:10 door Keizer Webdesign
- waar komt $playlist_id ineens vandaan?
- variabelen buiten quotes
- wat is eigenlijk je vraag?
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php
$pl = isset($_GET['playlist']) ? $_GET['playlist'] : false;
$playlists = array('minecraft'=>'B96604659AE908B9', enz.);
if (!$pl || !array_key_exists($pl, $playlists))
{
echo "selecteer een playlist";
}
else
{
$url = "https://gdata.youtube.com/feeds/api/playlists/" . $playlists[$pl] . "?v=2&alt=json";
$data = json_decode(file_get_contents($url),true);
$info = $data["feed"];
$video = $info["entry"];
$nVideo = count($video);
echo 'Let\'s play' . $info['title'][$t].'<br/><hr><br/>';
for($i=0;$i<9;$i++)
{
echo '<div class="playlist-video"><a href="' . $video[$i]['link'][0]['href'] . '"><img style="width: 100%;" src="' . $video[$i]['media' . $group]['media' . $thumbnail][1]['url'] . '" /></a><br />';
echo 'Name: ' . $video[$i]['title'][$t] . '<br/><hr><div>';
}
}
?>
$pl = isset($_GET['playlist']) ? $_GET['playlist'] : false;
$playlists = array('minecraft'=>'B96604659AE908B9', enz.);
if (!$pl || !array_key_exists($pl, $playlists))
{
echo "selecteer een playlist";
}
else
{
$url = "https://gdata.youtube.com/feeds/api/playlists/" . $playlists[$pl] . "?v=2&alt=json";
$data = json_decode(file_get_contents($url),true);
$info = $data["feed"];
$video = $info["entry"];
$nVideo = count($video);
echo 'Let\'s play' . $info['title'][$t].'<br/><hr><br/>';
for($i=0;$i<9;$i++)
{
echo '<div class="playlist-video"><a href="' . $video[$i]['link'][0]['href'] . '"><img style="width: 100%;" src="' . $video[$i]['media' . $group]['media' . $thumbnail][1]['url'] . '" /></a><br />';
echo 'Name: ' . $video[$i]['title'][$t] . '<br/><hr><div>';
}
}
?>
Waar haal je $t vandaan?
Gewijzigd op 15/05/2013 22:25:41 door Nick Dijkstra
Hartstikke bedankt Nick!!
Toevoeging op 15/05/2013 22:27:50:
Haha eigenlijk geen idee, ik plukte het scriptje van het web:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
//Playlist: PLB96604659AE908B9, remove PL from name
$playlist_id = "B96604659AE908B9";
$url = "https://gdata.youtube.com/feeds/api/playlists/".$playlist_id."?v=2&alt=json";
$data = json_decode(file_get_contents($url),true);
$info = $data["feed"];
$video = $info["entry"];
$nVideo = count($video);
echo "Let's play".$info["title"]['$t'].'<br/><hr><br/>';
for($i=0;$i<9;$i++){
echo "<div class=\"playlist-video\"><a href='".$video[$i]['link'][0]['href']."'><img style='width: 100%; ' src='".$video[$i]['media$group']['media$thumbnail'][1]['url']."' /></a><br />";
echo "Name: ".$video[$i]['title']['$t'].'<br/><hr><div>';
}
?>
//Playlist: PLB96604659AE908B9, remove PL from name
$playlist_id = "B96604659AE908B9";
$url = "https://gdata.youtube.com/feeds/api/playlists/".$playlist_id."?v=2&alt=json";
$data = json_decode(file_get_contents($url),true);
$info = $data["feed"];
$video = $info["entry"];
$nVideo = count($video);
echo "Let's play".$info["title"]['$t'].'<br/><hr><br/>';
for($i=0;$i<9;$i++){
echo "<div class=\"playlist-video\"><a href='".$video[$i]['link'][0]['href']."'><img style='width: 100%; ' src='".$video[$i]['media$group']['media$thumbnail'][1]['url']."' /></a><br />";
echo "Name: ".$video[$i]['title']['$t'].'<br/><hr><div>';
}
?>
Heb CURL gebruikt omdat op een of andere manier file_get_contents bij mij niet werkte.
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
$pl = isset($_GET['playlist']) ? $_GET['playlist'] : false;
$playlists = array('minecraft' => 'B96604659AE908B9');
if (!$pl || !array_key_exists($pl, $playlists))
{
echo "selecteer een playlist";
}
else
{
$url = "https://gdata.youtube.com/feeds/api/playlists/" . $playlists[$pl] . "?v=2&alt=jsonc";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = json_decode(curl_exec($ch), true);
curl_close($ch);
$info = $data["data"];
$videos = $info["items"];
echo 'Let\'s play ' . $info['title'] . '<br/><hr><br/>';
foreach ($videos as $video)
{
echo '<div class="playlist-video"><a href="' . $video['video']['player']['default'] . '&list=' . $info['id'] . '"><img src="' . $video['video']['thumbnail']['sqDefault'] . '" /></a><br />';
echo 'Name: ' . $video['video']['title'] . '<br/><hr><div>';
}
}
?>
$pl = isset($_GET['playlist']) ? $_GET['playlist'] : false;
$playlists = array('minecraft' => 'B96604659AE908B9');
if (!$pl || !array_key_exists($pl, $playlists))
{
echo "selecteer een playlist";
}
else
{
$url = "https://gdata.youtube.com/feeds/api/playlists/" . $playlists[$pl] . "?v=2&alt=jsonc";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = json_decode(curl_exec($ch), true);
curl_close($ch);
$info = $data["data"];
$videos = $info["items"];
echo 'Let\'s play ' . $info['title'] . '<br/><hr><br/>';
foreach ($videos as $video)
{
echo '<div class="playlist-video"><a href="' . $video['video']['player']['default'] . '&list=' . $info['id'] . '"><img src="' . $video['video']['thumbnail']['sqDefault'] . '" /></a><br />';
echo 'Name: ' . $video['video']['title'] . '<br/><hr><div>';
}
}
?>
Bedankt!