Skip to content

Instantly share code, notes, and snippets.

@rev087
Created December 22, 2011 21:56
Show Gist options
  • Save rev087/1512028 to your computer and use it in GitHub Desktop.
Save rev087/1512028 to your computer and use it in GitHub Desktop.
<?php
// Prepare the API call
$search_string = urlencode("City of God");
$API_KEY = "<redacted>";
$URL = "http://api.themoviedb.org/2.1/Movie.search/en/xml/{$API_KEY}/{$search_string}";
// Perform the API call
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
// Parse the XML response
$doc = new DOMDocument();
@$doc->loadHTML($output);
// Traverse the DOM node tree
$movies = $doc->getElementsByTagName("movie");
for ($i=0; $i<$movies->length; $i++) {
$movie = $movies->item($i);
$overview = $movie->getElementsByTagName("overview")->item(0);
var_dump($overview->textContent);
}
?>
@rev087
Copy link
Author

rev087 commented Dec 22, 2011

string(248) "City of God is one of the most successful Brazilian films of all times. It depicts the raw violence in the ghettos of Rio de Janeiro in the 1970’s that even had young kids carrying guns and joining gangs when they should be playing hide-and-seek."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment