By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,748 Members | 1,570 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,748 IT Pros & Developers. It's quick & easy.

fsockopen() help

P: n/a
Hi all,

I'm trying to open, read and extract information from a website
(maximum and minimum temps from
http://www.bom.gov.au/cgi-bin/wrap_fwo.pl?IDV10450.txt )... Could
anyone give me some direction in how to do this? Below is the code I
have written but i keep get given an 'invalid stream resource' error

Thanks for any help! :)
Nima

<?php

$page = "www.bom.gov.au/cgi-bin/wrap_fwo.pl?IDV10450.txt";
$time_limit = 60;
$file = fsockopen($page, $errno, $error, $time_limit);
if(!fp){
echo("Connection failure");
}
else
{
fputs($file, "GET / HTTP/1.0\r\n\r\n");
while (!feof($file)){
$data[] = fgets($file, 1000);
}
fclose($file);
}
?>

Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Nima wrote:
Hi all,

I'm trying to open, read and extract information from a website (maximum
and minimum temps from
http://www.bom.gov.au/cgi-bin/wrap_fwo.pl?IDV10450.txt )... Could anyone
give me some direction in how to do this? Below is the code I have
written but i keep get given an 'invalid stream resource' error

Thanks for any help! :)
Nima

<?php

$page = "www.bom.gov.au/cgi-bin/wrap_fwo.pl?IDV10450.txt";
$time_limit = 60;
$file = fsockopen($page, $errno, $error, $time_limit);
This is wrong for two reasons. First, you can't connect to the server
using the URL and you must give a valid port to connect to (usually 80).
if(!fp){
echo("Connection failure");
}
else
{
fputs($file, "GET / HTTP/1.0\r\n\r\n");
while (!feof($file)){
$data[] = fgets($file, 1000);
}
fclose($file);
}
?>


Try *fopen* on your url, it should work. For later information, see
<http://fr3.php.net/manual/en/function.fopen.php>

--
Guillaume Brocker
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.