Home     Articles & Projects     Products & Web Services

Trying to get the following info

Hi Guys, I am trying to get some data from this page but not quite sure how to go about it,
The URL is {link saved}
Info I am trying to get is the data that looks like this (Might be a bit different)
But the Update, Surf, Wind and Weather stays the same just the parts after :

Updated: Fri Jan 1st, 7:03am
Surf: clean 0.5-1ft
Wind: light
Weather: partly cloudy

I also want to get the following data (you will have to look in the source code for this info)

{code saved}

I need to then strip all of the data after .swf?
If you can help that would be great.

Thanks

Can anyone help?

Can anyone help?

Hi Russell, Take a look at

Hi Russell,

Take a look at parse_str() that will enable you to take the URL and extract all the name=value pairs into (I would recommend) an array...

Cheers,
David.

I am hoping you might be

I am hoping you might be able to help, This code works fine but I need to take what it shows and split it, for entry into my database.

{code saved}

If you can help that would be great.
Thanks

Hi Russell, Could you

Hi Russell,

Could you perhaps post a sample of the data you are trying to split and I'll take a look...!

Cheers,
David.

array(43) { ["day"]=>

array(43) { ["day"]=> string(1) "2" ["amht1"]=> string(4) "3.50" ["pmht1"]=> string(4) "2.50" ["amwind1"]=> string(1) "w" ["pmwind1"]=> string(3) "wnw" ["am_wind_strength1"]=> string(2) "20" ["pm_wind_strength1"]=> string(2) "10" ["amht2"]=> string(1) "2" ["pmht2"]=> string(1) "3" ["amwind2"]=> string(2) "nw" ["pmwind2"]=> string(2) "sw" ["am_wind_strength2"]=> string(2) "20" ["pm_wind_strength2"]=> string(2) "25" ["amht3"]=> string(4) "2.50" ["pmht3"]=> string(4) "2.50" ["amwind3"]=> string(3) "wnw" ["pmwind3"]=> string(1) "s" ["am_wind_strength3"]=> string(1) "0" ["pm_wind_strength3"]=> string(2) "10" ["amht4"]=> string(1) "2" ["pmht4"]=> string(1) "2" ["amwind4"]=> string(1) "n" ["pmwind4"]=> string(2) "sw" ["am_wind_strength4"]=> string(1) "0" ["pm_wind_strength4"]=> string(2) "10" ["amht5"]=> string(1) "2" ["pmht5"]=> string(4) "4.50" ["amwind5"]=> string(1) "w" ["pmwind5"]=> string(2) "sw" ["am_wind_strength5"]=> string(2) "10" ["pm_wind_strength5"]=> string(2) "20" ["amht6"]=> string(1) "4" ["pmht6"]=> string(1) "3" ["amwind6"]=> string(1) "w" ["pmwind6"]=> string(2) "sw" ["am_wind_strength6"]=> string(2) "10" ["pm_wind_strength6"]=> string(2) "20" ["amht7"]=> string(4) "3.50" ["pmht7"]=> string(4) "3.50" ["amwind7"]=> string(1) "w" ["pmwind7"]=> string(1) "w" ["am_wind_strength7"]=> string(1) "0" ["pm_wind_strength7"]=> string(1) "0" }

Hi Russell, As the keys /

Hi Russell,

As the keys / values you require all appear within quotation marks, it's easy to extract them using preg_match_all; and then create your own associative array from the matches. Try this:

<?php
  header
("Content-Type: text/plain");
 
$data = '...data to extract...';
 
preg_match_all('/"(.*?)"/',$data,$matches);
 
$params = array();
 
$j = count($matches[0]);
  for(
$i=0;$i<$j;$i+=2)
  {
   
$params[$matches[0][$i]] = $matches[0][$i+1];
  }
 
print_r($params);
?>

...(replace "...data to extract..." with the data from your post of course) and you should get this:

Array
(
    ["day"] => "2"
    ["amht1"] => "3.50"
    ["pmht1"] => "2.50"
    ["amwind1"] => "w"
    ["pmwind1"] => "wnw"
    ["am_wind_strength1"] => "20"
    ["pm_wind_strength1"] => "10"
    ["amht2"] => "2"
    ["pmht2"] => "3"
    ["amwind2"] => "nw"
    ["pmwind2"] => "sw"
    ["am_wind_strength2"] => "20"
    ["pm_wind_strength2"] => "25"
    ["amht3"] => "2.50"
    ["pmht3"] => "2.50"
    ["amwind3"] => "wnw"
    ["pmwind3"] => "s"
    ["am_wind_strength3"] => "0"
    ["pm_wind_strength3"] => "10"
    ["amht4"] => "2"
    ["pmht4"] => "2"
    ["amwind4"] => "n"
    ["pmwind4"] => "sw"
    ["am_wind_strength4"] => "0"
    ["pm_wind_strength4"] => "10"
    ["amht5"] => "2"
    ["pmht5"] => "4.50"
    ["amwind5"] => "w"
    ["pmwind5"] => "sw"
    ["am_wind_strength5"] => "10"
    ["pm_wind_strength5"] => "20"
    ["amht6"] => "4"
    ["pmht6"] => "3"
    ["amwind6"] => "w"
    ["pmwind6"] => "sw"
    ["am_wind_strength6"] => "10"
    ["pm_wind_strength6"] => "20"
    ["amht7"] => "3.50"
    ["pmht7"] => "3.50"
    ["amwind7"] => "w"
    ["pmwind7"] => "w"
    ["am_wind_strength7"] => "0"
    ["pm_wind_strength7"] => "0"
)

Hope this helps!
Cheers,
David.