2

I found this code snippet to retrieve the title from a YouTube video and it works,

<?php
$video_id = 'y8Kyi0WNg40';
$content = file_get_contents("http://youtube.com/get_video_info?video_id=" . $video_id);
parse_str($content, $ytarr);
echo $ytarr['title'];
?>

however many people say that this method is not safe for some reason and they should use cURL with YouTube's API, can you please explain why this method(file_get_contents) is not safe.

And if so I will appreciate a link to a tutorial or example on using cURL to achieve the same results as the code above.

grasshopper
  • 1,381
  • 4
  • 19
  • 36

1 Answers1

2

You can use file_get_contents("http://gdata.youtube.com/feeds/api/videos/".$video_id); to parse more easily since is XML format

If you want to use cURL try this tutorial

Ciro
  • 662
  • 7
  • 19