0

I am trying to request a youtube array, but the var dump reveals a dump starting with object(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>";
?>

2 Answers 2

1

You've misplaced the right parenthesis in this line:

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

should be

$youtube_array = json_decode(file_get_contents("-" . urlencode($music)), TRUE );
Sign up to request clarification or add additional context in comments.

Comments

0

json_decode has a second parameter ([, bool $assoc = false ....). If it is left at the default, it will return an object. With it true, it sets an associative array.

Your code has the 'true' in with the 'file_get_contents($filename [, bool $use_include_path...'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.