http://gdata.youtube.com/feeds/users/LadyGagaVEVO/uploads?alt=json&max-results=10&format=5

I would like to extract the video thumbnail and video link using PHP and JavaScript from the url above but I'm not sure how to do it, here is my attempt so far:

$json = 'http://gdata.youtube.com/feeds/users/LadyGagaVEVO/uploads?alt=json&max-results=10&format=5';
$data = json_decode($json);
print_r($data);
share|improve this question
Show some sample code of what you have tried. – nickb Apr 23 '12 at 23:44
"i can't find the answers" Then find better tutorials. – Ignacio Vazquez-Abrams Apr 23 '12 at 23:46
i edited it and shown some code – Jetoox Apr 23 '12 at 23:50

closed as not a real question by casperOne Oct 2 '12 at 15:58

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, see the FAQ.

3 Answers

up vote 0 down vote accepted

in PHP

  $tmp = file_get_contents('http://gdata.youtube.com/feeds/users/LadyGagaVEVO/uploads?alt=json&max-results=10&format=5/');
  $data = json_decode($tmp,true);

in javascript with jquery

  $.get("http://gdata.youtube.com/feeds/users/LadyGagaVEVO/uploads?alt=json&max-results=10&format=5/", function(response) { 
       var data = $.parseJSON(response);
  });

about the illegal character, depends on what counts as illegal in your case, just do some string validation as you traverse through the object for the thumbnail and video link you looking for.

share|improve this answer
i tried to print_r the $data but nothing happens – Jetoox Apr 24 '12 at 0:11
opps sorry added an extra / at the end of the url. remove that and it all should work. same with the url in the javascript part. – Gäng Tian Apr 24 '12 at 19:09

PHP: json_decode()

JavaScript is the exact same, pretty much, just with JSON.parse() and no special arguments past the data.

There is no better tutorial than the documentation ;)

share|improve this answer

Using, PHP as you are doing, use json_decode(). but use it one extra paramter

$data = json_decode($string, true); // the true in the last will change into associative array

For JavaScript, as Kolink said, use JSON.parse()

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.