A Guide to Mobile and Web Technology(LAMP)

The following are the different ways of reading a web page or external file contents in php.

$pageurl = "http://google.com";

//First Method

$r = new HTTPRequest($pageurl);
$html = $r->DownloadToString();
echo $html;

//Second Method

$html =file_get_contents($pageurl);
echo $html;

//Third Method (Using Curl) For this curl support should be enabled.

echo phpinfo();

//to check whether curl is enabled or not.

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
// DO NOT RETURN HTTP HEADERS
curl_setopt($ch, CURLOPT_HEADER, 0);  
 // RETURN THE CONTENTS OF THE CALL
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$res=curl_exec($ch);
curl_close($ch);
print_r($res[2]);

Comments on: "Read webpage or external file contents in php" (1)

  1. Awesome blogpost, I didn’t thought this was going to be so amazing when I saw your title with link!

Leave a comment