All about PHP/MySQL

Thursday, February 5, 2009

Fetch a URL (with cURL)

cURL is a very useful PHP library which can be used to connect to different types of servers with different types of protocols. Here is a very basic example of its primary usage.

function fetchPage($url)

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$responce = curl_exec($ch);
curl_close ($ch);

$data =$responce;

return $data;


$page_data = fetchpage("");

echo $page_data;

You can do the magic by using Regular Expressions on the data stored in $page_data variable.

See this post of my kind friend Mr. Siddique Ahmed on crawling guide using Simple Html DOM Class.

Happy Coding :)


Post a Comment

Subscribe to Post Comments [Atom]

Links to this post:

Create a Link

<< Home