0

I have this link

http://gdata.youtube.com/feeds/api/users/gudjondaniel/uploads?max-results=1

That gives me the latest video from GudjoDaneel but I'd like to print our this title inside a PHP file

<title type='text'>The GD Project S3 | NEVER GIVE UP! | Division 1</title><content type='text'>

I'd appreciate it if someone could help me where to begin. And what I could look up.

IamGretar
  • 173
  • 2
  • 13

1 Answers1

1

I'd suggest looking up SimpleXML. It's easy to use once you get the hang of it, and you can get the title in just four line:

$url    = 'http://gdata.youtube.com/feeds/api/users/gudjondaniel/uploads?max-results=1';
$source = file_get_contents($url);
$xml    = new SimpleXMLElement($source);
$title  = $xml->entry->title;

Do note, though, that $title is a PHP object in this case. If you echo it straight away, it'll be reinterpreted as a string, and everything will be alright. If you plan on doing anything else with it, you'll need to cast it as a string, like this:

$title = strval($title);
Joel Hinz
  • 24,719
  • 6
  • 62
  • 75
  • Do you know how I could get the viewCount ? – IamGretar Jun 18 '13 at 22:39
  • Your answer was not helpful, it only [created the next question](http://stackoverflow.com/questions/17180080/getting-viewcount-from-xml). Instead please take care to not feed help vampires, just leave a comment linking the manual for example is a good working method to prevent "asking through" help vampires. – hakre Jun 19 '13 at 05:26
  • I decided to give them the benefit of a doubt - at least this question was put in the form of "could you please give me some directions" instead of "please do everything for me". Apparently I was wrong in this case. – Joel Hinz Jun 19 '13 at 07:44