amount Posted February 17, 2007 Share Posted February 17, 2007 Hi, I'm trying to set up a messageboard/blog where people can log surfing sessions. As part of this I would like to have a generic form where people can enter their comments as well as give a specific time of their session. With the given time, I would like to have a script that would automatically retrieve data from an NOAA buoy feed (particularly, this one: http://www.ndbc.noaa.gov/data/realtime2/41002.spec ) and have the relevant data pasted onto the text of their blog entry. For example, if somebody went surfing at 1:00 PM on February 16, I would want the script to access the buoy feed, find the relevant line (for the time) and column (for the category, such as SwH for "Swell Height") and past text to the post (such as: "Swell Height = x"). This is also in the very early development stages, so I'm not sure what kind of bulletinboard/blog software I should use (preferably something free!). I'm a bit of a newbie at this, so any information (and simple language) would be greatly appreciated. Thanks a bunch! --Andre Quote Link to comment Share on other sites More sharing options...
fert Posted February 17, 2007 Share Posted February 17, 2007 your best bet would be http://us2.php.net/manual/en/function.explode.php http://us2.php.net/manual/en/function.preg-match-all.php Quote Link to comment Share on other sites More sharing options...
sspoke Posted February 17, 2007 Share Posted February 17, 2007 http://us3.php.net/manual/en/function.fsockopen.php for the retrieving the data Quote Link to comment Share on other sites More sharing options...
fert Posted February 17, 2007 Share Posted February 17, 2007 or you could use fopen Quote Link to comment Share on other sites More sharing options...
linuxdream Posted February 17, 2007 Share Posted February 17, 2007 Also ripCURL http://sourceforge.net/projects/ripcurl will let you get the page and has data parsing methods to pull whatever might need. Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted February 17, 2007 Share Posted February 17, 2007 This code should work...although since it takes a bit to process all of the text data you will want to cache the data from noaa and refresh it every hour or so to avoid excess traffic and processing on your server. //get the data $wave_data = file("http://www.ndbc.noaa.gov/data/realtime2/41002.spec"); $lines = count($wave_data); //strip extra spaces from the first line $columns = preg_replace('/\s\s+/', ' ', $wave_data[0]); //get the column data $columns = explode(" ", trim($columns)); for ($i = 1; $i < $lines; $i++) { //strip extra spaces from the line $line = preg_replace('/\s\s+/', ' ', $wave_data[$i]); //explode into elements $line = explode(" ", trim($line)); $cnt = count($line); //build an array where we can reference the data for ($j = 3; $j < $cnt; $j++) { $data[$line[0]][$line[1]][$line[2]][$line[3]][$columns[$j]] = $line[$j]; } } //with the above array, we can reference the data in the following way: $year = '2007'; $month = '02'; $day = '16'; $hour = '20'; echo $data[$year][$month][$day][$hour]['SwH']; echo $data[$year][$month][$day][$hour]['STEEPNESS']; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.