Fetching 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 to fetch a page.

<?php
$c = curl_init('http://www.w3mentor.com/robots.txt');
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
$page = curl_exec($c);
curl_close($c);
?>
Share Article/Example:
  • DotNetKicks
  • DZone
  • StumbleUpon
  • Print
  • Add to favorites
  • Digg
  • del.icio.us
  • Twitter
  • Facebook
  • LinkedIn
  • Posterous
  • Slashdot

 

 
eXTReMe Tracker