Array ( [0] =>

Discussion in 'PHP' started by Egnited, Jun 15, 2008.

  1. #1
    I'm trying to scrape info from this webpage:
    http://mobile.weather.gov/port_mp_ns.php?select=3&CityName=Wichita&site=ICT&State=KS&warnzone=KSZ083

    I just want to pull the following lines:

    Last Update: 06/12/08, 09:53 AM CDT
    Weather: Mostly Cloudy
    Temperature: 79°F (26°C)
    Humidity: 67 %
    Wind Speed: S 9 MPH


    My current code is:
    
    <?php
    $data = file_get_contents('http://mobile.weather.gov/port_mp_ns.php?select=3&CityName=Wichita&site=ICT&State=KS&warnzone=KSZ083');preg_match_all("/Weather:(.*)<br>.*Temperature:(.*)<br>.*Humidity:(.*)<br>.*Wind Speed:(.*)<br>/Usm",$data,$results);
    print_r($results[0]);
    ?>
    Code (markup):
    This code works fine to pull the info, but for some reason it's displaying "Array ( [0] =>"..... as shown here: www.egnited.net.


    What should I change the code to so I can get rid of that "Array" thing?


    Any help would be GREATLY appreciated.... I've spent about ten hours now trying to figure it out.

    Thanks.
     
    Egnited, Jun 15, 2008 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    EricBruggema, Jun 15, 2008 IP
  3. Egnited

    Egnited Well-Known Member

    Messages:
    792
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    110
    #3
    I'm sorry but I've read that and am not talented enough to figure it out. :(

    Could someone please fix the code so that it'll display the info without the "Array" thing?
     
    Egnited, Jun 15, 2008 IP
  4. ToddMicheau

    ToddMicheau Active Member

    Messages:
    183
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    58
    #4
    Heh, try this:

    
    <?php
    $data = file_get_contents('http://mobile.weather.gov/port_mp_ns.php?select=3&CityName=Wichita&site=ICT&State=KS&warnzone=KSZ083');preg_match_all("/Weather:(.*)<br>.*Temperature:(.*)<br>.*Humidity:(.*)<br>.*Wind Speed:(.*)<br>/Usm",$data,$results);
    echo $results[0][0];
    ?>
    
    PHP:
    Is that what you were looking for? Since it's an array within an array you just echo the second layer ($result[0][0];)

    =]
     
    ToddMicheau, Jun 15, 2008 IP