note 40803 deleted from function.fopen by nlopess
| From: | nlopess@php.net | Date: | Mon, 15 Mar 2004 14:06:40 +0000 |
| Subject: | note 40803 deleted from function.fopen by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-66863@lists.php.net to get a copy of this message | ||
Note Submitter: lmaxcar@yahoo.com.br
----
fopen() will not work (PHP <= 4.3.3) getting data from a URL + QUERY_STRING, like:
http://www.example.com/example.php?IdCategory=4
or http://www.receitas.com.br/Receitas.asp?Receita=Caipirinha
A solution I found to do that is to use functions of CURL Library.
I think CURL get HTML final result of webserver... fopen() try to open file.
<?php
//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