Support Forums
IMDB rating using cURL and PHP - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: PHP The Hypertext Preprocessor (https://www.supportforums.net/forumdisplay.php?fid=21)
+---- Thread: IMDB rating using cURL and PHP (/showthread.php?tid=28093)



IMDB rating using cURL and PHP - sarvsav - 08-25-2013

A script to find the rating of any imdb movie.

How to use,

php imdb.php <movie name>

Ex :

$ php imdb.php trtanic
Your movie Titanic (1997) has 7.6 ratings.

PHP Code:
<?php
///////////////////////////////////////////////
////////  Author : Sarvsav Sharma  ///////////
//////// Email : sarvsav@gmail.com //////////
////////////////////////////////////////////
$characters count($argv)-1;
if(isset(
$argv[1]))
$movie_name=$argv[1]."+";
else
exit(
0);
for(
$i=2;$i<$characters+1;$i++)
$movie_name.= $argv[$i]."+";
$ch curl_init();
curl_setopt($ch,CURLOPT_URL,'https://www.google.co.in/search?q='.$movie_name.'imdb');
curl_setopt($chCURLOPT_RETURNTRANSFER1);
$movie_link curl_exec($ch);
preg_match('#www\.imdb\.com\/title\/tt\d+#',$movie_link,$matchme);
$imdb_url $matchme[0];
curl_setopt($ch,CURLOPT_URL,$imdb_url."/");
$movie_data =  curl_exec($ch);
curl_close($ch);
preg_match('#ratingValue\"\>\d\.\d#',$movie_data,$matches);
$rating explode(">",$matches[0]);
$name $movie_data;
preg_match('#<title>.+</title>#',$name,$name_match);
$name_match explode(")",$name_match[0]);
$name_match explode(">",$name_match[0]);
echo 
"Your movie ".$name_match[1].") "."has ".$rating[1]." ratings.\n";

?>

Skype : Sarvsav Sharma


RE: IMDB rating using cURL and PHP - Callum - 04-15-2014

Looks good - looks like you've got a good script here.