I'm working on an idea to grab data from a text file with a bunch of space separated values that contains data from buoy reports at NOAA. Unlike their weather feeds, they don't serve up XML buoy data.
Here's the file I'm trying to grab: http://www.ndbc.noaa.gov/data/realtime2/41004.spec
I've tried several methods, and the one that seemed to have the most promise tried to make a socket connection:
<?php
$host = "http://www.ndbc.noaa.gov";
$page = "/data/realtime2/41004.spec";
$fp = fsockopen($host, 80, $errno, $errdesc) or
die("Connection to $host failed");
$request = "GET $page HTTP/1.0\r\n";
$request .= "Host: $host\r\n";
$request .= "Referer: $host\r\n";
fputs($fp, $request);
while(!feof($fp)){
$page[] = fgets($fp, 1024);
}
fclose($fp);
for($i=0; $i < count($page); $i++){
$data .= $page[$i];
}
?>
But all I get is this:
I've been flailing around for a few hours now, but I'm out of new ideas.
Once I get the data, I'm planning to throw it all into an array and/or MySQL db and only grab it once per hour max. And go from there.
Any ideas?