note 70288 deleted from function.fopen by bjori
| From: | bjori@php.net | Date: | Fri, 08 Dec 2006 07:19:33 +0000 |
| Subject: | note 70288 deleted from function.fopen by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-120424@lists.php.net to get a copy of this message | ||
Note Submitter: http://www.havarnielsen.com
----
/* If you want to use parts of or an entire external page in your site, you can use this function to
fetch it using either curl or fopen. The output buffer functions used in the curl section enables
you to strip or format parts of the page before it is printed to the browserwindow. Curl is
recommended in most cases if php has been compiled to enable curl. It will take load off the server
and may prevent some hacking attempts.
// usage (for curl):
$data = open_external_url("http://www.php.net");
// (for fopen):
$data = open_external_url("http://www.php.net",
"fopen");
// use strpos, stristr, ereg_replace or any other string manipulation functions to strip
<body> or <html> or other elements.
echo $data;
*/
function open_external_url($url, $method = "curl")
{
$data = '';
if(strtolower($method) == "curl")
{
$ch = curl_init($url);
ob_start();
curl_exec($ch);
curl_close($ch);
$data = ob_get_contents();
ob_end_clean();
}
else if(strtolower($method) == "fopen")
{
$file = fopen($url, "r");
while(!feof($file)) {
$data = $data . fgets($file, 4096);
}
fclose ($file);
}
return $data;
}