Support Forums

Full Version: IMDB rating using cURL and PHP
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
Looks good - looks like you've got a good script here.