Skip to content

Instantly share code, notes, and snippets.

@unusorin
Forked from silalahi/imdb.php
Created September 19, 2012 13:02
Show Gist options
  • Save unusorin/3749531 to your computer and use it in GitHub Desktop.
Save unusorin/3749531 to your computer and use it in GitHub Desktop.
IMDb Wrapper Class PHP
<?php
/**
* IMDB Wrapper API
* Wrapper class to retrieve data from IMDB
* http://jogisilalahi.com/blog/imdb-api-wrapper-class-php
* @author Jogi Silalahi <silalahi.jogi@gmail.com>
*/
class IMDB
{
/**
* IMDB API URL
* @version 2.0
*/
private $APIURL = "http://www.imdbapi.com";
/**
* Server response
* Handling server response
*/
private $response;
/**
* Search
* Searching movie information
* @param string Movie Title
* @param string Movie Year (optional)
* @param string Plot of movie (short or full)
*/
public function search($title, $year='', $plot='full')
{
// Preparing full URL
$full_url = $this->APIURL . '?t=' . urlencode($title) . '&y=' . $year . '&plot=' . $plot;
// Fetch JSON and decoding
$result = json_decode(file_get_contents($full_url));
// Assigning as this vars
$vars = get_object_vars($result);
foreach($vars as $key=>$value)
{
$this->{strtolower($key)} = $value;
}
}
/**
* Exists
* Checking if movie information was exists
* @return bool
*/
public function exists()
{
if($this->response == "True")
{
$this->response = TRUE;
}
else
{
$this->response = FALSE;
}
return $this->response;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment