Tuesday, January 23, 2007

How to get contents of a remote URL using PHP?

/************** Method 1 ******************/
$request = 'www.remoteurl.com';
$response = file_get_contents($request);
/************** Method 1 ******************/

/************** Method 2 ******************/
$filename = "www.remoteurl.com";
$handle = fopen($filename, "rb");

$response="";

if ($handle) {
while (!feof($handle)) {
$response .= fgets($handle);
}
fclose($handle);
}
/************** Method 2 ******************/

No comments: