note 40656 deleted from function.fopen by nlopess
| From: | nlopess@php.net | Date: | Thu, 11 Mar 2004 15:00:30 +0000 |
| Subject: | note 40656 deleted from function.fopen by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-66656@lists.php.net to get a copy of this message | ||
Note Submitter:
----
fopen() will not work getting data from a URL with paramethers, like:
http://www.example.com/example.php?IdCategory=4
A solution I found to do that is to use functions of CURL Library.
Example:
Does not work using fopen():
$url = "http://www.example.com/example.php?IdCategory=4";
function extrair_url_fopen ($url)
{
$filename = $url;
$handle = fopen ($filename, "r");
$conteudo = fread ($handle, filesize ($filename));
fclose ($handle);
return $conteudo;
}
It works using CURL:
$url = "http://www.example.com/example.php?IdCategory=4";
function extrair_url_curl ($url)
{
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_HEADER, 0);
ob_start();
curl_exec ($ch);
curl_close ($ch);
$string = ob_get_contents();
ob_end_clean();
return $string;
}
Luiz Miguel Axcar
Campinas, São Paulo, Brasil
PHP [enguin] never sleeps