Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class getImdbInfo{
- private $id;
- private $initial_data;
- private $title;
- private $Year;
- private $Released;
- private $Runtime;
- private $Genre;
- private $Director;
- private $Writer;
- private $Actors;
- private $Plot;
- private $Poster;
- private $imdbRating;
- private $imdbVotes;
- function __construct($link){
- if(filter_var($link, FILTER_VALIDATE_URL)){
- preg_match('(/title/(tt\d{5,7})/)u', $link, $matches, PREG_OFFSET_CAPTURE);
- $this->id = $matches[1][0];
- }else{
- throw new Exception('That doesn\'t look like a valid URL.');
- }
- }
- public function getData(){
- $get_movie_info = file_get_contents("http://www.omdbapi.com/?i=".$this->id);
- $this->initial_data = json_decode($get_movie_info);
- $this->title = $this->initial_data->Title;
- $this->Year = $this->initial_data->Year;
- $this->Released = $this->initial_data->Released;
- $this->Runtime = $this->initial_data->Runtime;
- $this->Genre = $this->initial_data->Genre;
- $this->Director = $this->initial_data->Director;
- $this->Writer = $this->initial_data->Writer;
- $this->Actors = $this->initial_data->Actors;
- $this->Plot = $this->initial_data->Plot;
- $this->Poster = $this->initial_data->Poster;
- $this->imdbRating = $this->initial_data->imdbRating;
- $this->imdbVotes = $this->initial_data->imdbVotes;
- }
- public function retArr(){
- $movie_info = array(
- 'title' => $this->title,
- 'year' => $this->Year,
- 'release date' => $this->Released,
- 'runtime' => $this->Runtime,
- 'genres' => $this->Genre,
- 'director' => $this->Director,
- 'writer' => $this->Writer,
- 'actors' => $this->Actors,
- 'plot' => $this->Plot,
- 'poster' => $this->Poster,
- 'rating' => $this->imdbRating,
- 'votes' => $this->imdbVotes
- );
- return $movie_info;
- }
- }
- //Cum functioneaza?
- //Preia link-ul imdb prin constructor si-si i-a ID-ul filmului
- try{
- $imdb = new getImdbInfo('http://www.imdb.com/title/tt0114746/?ref_=nv_sr_1');
- }catch (Exception $e){
- echo $e->getMessage();
- }
- //Din id-ul filmului preluat in constructor preia informatiile cu ajutorul http://www.omdbapi.com/
- $imdb->getData();
- //creeaza un vector cu toate informatiile filmului
- $arr = $imdb->retArr();
- //parcurgem vectorul si afisam fiecare valoare...
- foreach( $arr as $a ){
- echo $a."<br/>";
- }
Add Comment
Please, Sign In to add comment