2012-05-08 9 views
0

我想申請一個YouTube的陣列,但VAR轉儲揭示了轉儲開始對象(stdClass的)#1

<?php 
$num = Rand(1,5); 
switch ($num) { 
case 1: header('Foo Fighters The Pretender'); $music= 'Foo Fighters The Pretender'; 
case 2: header('Arctic Monkeys Flourescent Adolescent'); $music= 'Arctic Monkeys Flourescent Adolescent'; 
case 3: header('The Strokes Under Cover of Darkness'); $music= 'under cover of darkness'; 
case 4: header('The White Stripes Seven Nation Army'); $music= 'the white stripes seven nation army'; 
case 5: header('Franz Ferdinand Michael'); $music= 'franz ferdinand michael'; 
} 
$youtube_array = json_decode(file_get_contents("https://gdata.youtube.com/feeds/api/videos?alt=json&q=" . urlencode($music) , TRUE)); 
var_dump($youtube_array); 
echo "<h1>Your Song Is:</h1>"; 
echo $music; 
echo "</p>"; 
echo "YouTube found this video about your Rock:"; 
echo "</p>"; 
$link = $youtube_array['feed']['entry'][0]['id']['$t']; 
$link2 = substr($link, 42); 
echo "<iframe width='960' height='720' src='http://www.youtube.com/embed/" . $link2 . "' frameborder='0' allowfullscreen></iframe>"; 
?> 

回答

1

你「VE錯位的該行的右括號:

$youtube_array = json_decode(file_get_contents("-" . urlencode($music) , TRUE)); 

應該

$youtube_array = json_decode(file_get_contents("-" . urlencode($music)), TRUE); 
+0

感謝「真」 !!!!你是最好的! – user1382567

0

json_decode^h作爲第二個參數([,bool $ assoc = false ....)。如果它保留在默認狀態,它將返回一個對象。有了它,它設置了一個關聯數組。

你的代碼中有與「file_get_contents($filename [, bool $use_include_path...

相關問題