I am trying to learn how to use PHP cURL and I am following a tutorial and while using Wamp. I am going to localhost and I never see the result of the code no matter the changes I do, all I see is:
This is my code:
<html>
<head>
</head>
<body>
<?php
function curl($url){
$options = Array(
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_FOLLOWLOCATION => TRUE,
CURLOPT_AUTOREFERER => TRUE,
CURLOPT_CONNECTTIMEOUT => 120,
CURLOPT_TIMEOUT => 120,
CURLOPT_MAXREDIRS => 10,
CURLOPT_USERAGENT => "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1a2pre) Gecko/2008073000 Shredder/3.0a2pre ThunderBrowse/3.2.1.8",
CURLOPT_URL => $url,
$ch = curl_init();
curl_setopt_array($ch, $options);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
function scrape_between($data, $start, $end){
$data= stristr($data, $start);
$data= substr($data, strlen($start));
$stop= stripos($data, $end);
$data= substr($data, 0, $stop);
return $data;
}
$scraped_page = curl("http://www.imdb.com"); // Downloading IMDB home page to variable $scraped_page
$scraped_data = scrape_between($scraped_page, "<title>", "</title>"); // Scraping downloaded dara in $scraped_page for content between <title> and </title> tags
echo $scraped_data; // Echoing $scraped data, should show "The Internet Movie Database (IMDb)"
?>
</body>
</html>