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]);
Advertisements

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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: