Hello,
I need some help. Ive got this script which scrapes the IMDB top 250 movies list. What Im trying to do is add a search link next to the year bit.
Ive got it partially working with str_replace but it only adds the link to the first movie. See here. (Pay attention to the actual URL of the search links)
So how would I make it add links to all the movies correctly. I was thinking preg_replace because I could use regex. But I have no idea how to use regex :confused:
Please help. Thanks :D Heres my script...
<?php
function get_inner_string($a,$b,$c)
{
$y = explode($b,$a);
$x = explode($c,$y[1]);
return $x[0];
}
//Get Page
$file = 'http://www.imdb.com/chart/top';
//Open Page
$open_file = file_get_contents($file);
//Find the list
$find_ad = get_inner_string($open_file, '<i>For this top 250, only votes from regular voters are considered.</i>', 'The formula for calculating the Top Rated 250 Titles gives a <b>true Bayesian estimate</b>:');
//Add http://www.imdb.com/ to the URL's
$new_page = str_replace('a href="/title/', 'a href="http://www.imdb.com/title/', $find_ad);
//Find movie name
$find_movie = get_inner_string($new_page, '/">', '</a>');
//Search URL
$search_url = '<a href="http://www.theflickzone.com/search.php?do=process&sortby=lastpost&titleonly=true&query=' . $find_movie . '"> Search </a>';
$replace_search = str_replace(')</font>', ') - ' . $search_url . '</font>', $new_page);
echo $replace_search;
?>