Page 1 of 1
Problems with reading content from the web using fopen()
Posted: Sat Nov 05, 2005 5:12 pm
by sandrol76
Jcart | Please use Code: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Hi all,
I used the following code to read the html response from a website but I can't understand why it doesn't work. Here is the code:
Code: Select all
$filename = "http://www.livescore.com/";
$handle = fopen($filename, "r");
$HTML = "";
while ($line = fgets ( $handle , 256 )) {
$HTML.= $line;
}
echo $HTML;
fclose($handle);
It does work with other web sites but not with that one. Can you help me with that?
Thank you in advance.
Jcart | Please use Code: Select all
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Posted: Sat Nov 05, 2005 5:16 pm
by John Cartwright
that host does not allows remote file opens with fopen based functions
try something along the lines of
Code: Select all
<?php
/*
* @return string
* @param string $url
* @desc Return string content from a remote file
* @author Luiz Miguel Axcar (lmaxcar@yahoo.com.br)
*/
function get_content($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;
}
#usage:
$content = get_content ("http://www.php.net");
var_dump ($content);
?>
Posted: Sat Nov 05, 2005 5:26 pm
by sandrol76
I tried that but I got the following error:
Fatal error: Call to undefined function: curl_init() on line 4
Any suggestion?
Posted: Sat Nov 05, 2005 5:30 pm
by John Cartwright
you have to have the cURL library installed on your server.. get it
here
Installation
Installation
To use PHP's CURL support you must also compile PHP --with-curl[=DIR] where DIR is the location of the directory containing the lib and include directories. In the "include" directory there should be a folder named "curl" which should contain the easy.h and curl.h files. There should be a file named libcurl.a located in the "lib" directory. Beginning with PHP 4.3.0 you can configure PHP to use CURL for URL streams --with-curlwrappers.
Note to Win32 Users: In order to enable this module on a Windows environment, you must copy libeay32.dll and ssleay32.dll from the DLL folder of the PHP/Win32 binary package to the SYSTEM folder of your Windows machine. (Ex: C:\WINNT\SYSTEM32 or C:\WINDOWS\SYSTEM)
Posted: Sat Nov 05, 2005 5:38 pm
by sandrol76
OK, thank you very much indeed for the help and for replying so quickly!
Posted: Mon Nov 07, 2005 12:40 pm
by SugahPie
Jcart wrote:you have to have the cURL library installed on your server.. get it
here
Installation
Installation
To use PHP's CURL support you must also compile PHP --with-curl[=DIR] where DIR is the location of the directory containing the lib and include directories. In the "include" directory there should be a folder named "curl" which should contain the easy.h and curl.h files. There should be a file named libcurl.a located in the "lib" directory. Beginning with PHP 4.3.0 you can configure PHP to use CURL for URL streams --with-curlwrappers.
Note to Win32 Users: In order to enable this module on a Windows environment, you must copy libeay32.dll and ssleay32.dll from the DLL folder of the PHP/Win32 binary package to the SYSTEM folder of your Windows machine. (Ex: C:\WINNT\SYSTEM32 or C:\WINDOWS\SYSTEM)
I am trying to install curl, but I have no clue what I'm doing and I can't find any specific instructions. What does "you must also compile PHP --with-curl[=DIR] where DIR is the location of the directory containing the lib and include directories" mean. Where do I do this and how? I'm assuming I'm supposed to edit a file and add that line or something, but what file do I edit and where in the file does this command go? Sorry for sounding like an idiot. Thanks for any help.
Posted: Mon Nov 07, 2005 10:20 pm
by egmax
file('your-files-url');

Posted: Mon Nov 07, 2005 10:26 pm
by feyd
is fopen() doesn't work, file() won't either.. just FYI..