Erok - 2009-05-13 18:18:54
I am creating a script that search imdb for a film based on a badly inputed film name. e.g.
$file="Madagascar-Escape.2.Africa[2008].cool_film [eng]";
$search = anafilm($file);
$q=str_ireplace(" ","+",$search['search']);
echo $url = "http://www.imdb.com/find?q=".$q.";s=tt";
$ch = curl_init(); // initialize curl handle
curl_setopt($ch, CURLOPT_URL,$url); // set url to post to
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 3); // times out after 4s
$result = curl_exec($ch); // run the whole process
curl_close($ch);
I made a function called anafilm() that analyses $file to extract the year and the language so "Madagascar Escape 2 Africa cool film" will be searched. I want to extract all the possible titles from the resulting page (http://www.imdb.com/find?q=Madagascar+Escape+2+Africa+cool+film) which is $result.
This is the first time i've used cUrl properly. Thanks