fsockopen() help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nima

    fsockopen() help

    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.go v.au/cgi-bin/wrap_fwo.pl?IDV 10450.txt";
    $time_limit = 60;
    $file = fsockopen($page , $errno, $error, $time_limit);
    if(!fp){
    echo("Connectio n failure");
    }
    else
    {
    fputs($file, "GET / HTTP/1.0\r\n\r\n");
    while (!feof($file)){
    $data[] = fgets($file, 1000);
    }
    fclose($file);
    }
    ?>

  • Guillaume Brocker

    #2
    Re: fsockopen() help

    Nima wrote:[color=blue]
    > 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.go v.au/cgi-bin/wrap_fwo.pl?IDV 10450.txt";
    > $time_limit = 60;
    > $file = fsockopen($page , $errno, $error, $time_limit);[/color]

    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).
    [color=blue]
    > if(!fp){
    > echo("Connectio n failure");
    > }
    > else
    > {
    > fputs($file, "GET / HTTP/1.0\r\n\r\n");
    > while (!feof($file)){
    > $data[] = fgets($file, 1000);
    > }
    > fclose($file);
    > }
    > ?>[/color]

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

    --
    Guillaume Brocker

    Comment

    Working...