I'm using php & cURL, to pull a Marine forecast from noaa's website. The script works fine until the forecast zone is more than 60 miles offshore. When the forecast is more than 60 miles offshore, the page redirects. My question is how do I get the new url and print only the info I want off the new page. Here is what I have so far. It obviously doesn't work but, I figured it might help show what I would like to accomplish.
<?php
$url = "http://forecast.weather.gov/MapClick.php?lat=$a1[d_lat]&lon=-$a1[d_lon]&unit=0&lg=english&FcstType=text&TextType=1";
//unique text to determine start goes here
$start = "</table><table width=";
//insert end text here
$end = "which includes this point<br></td></tr><tr>";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url );
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec ($ch) or die ("Couldn't connect to $url.");
curl_close ($ch);
$startposition = strpos($result,$start);
if($startposition > 0){
$endposition = strpos($result,$end, $startposition);
//add enough chars to include the tag
$endposition += strlen($end);
$length = $endposition-$startposition;
$result = substr($result,$startposition,$length);
echo $result;
}else
//get the new url from headers? This is where I'm Lost...
$url = "";
//unique text to determine start on redirected page
$start = "</table><table width=";
//insert end text here
$end = "which includes this point<br></td></tr><tr>";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url );
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec ($ch) or die ("Couldn't connect to $url.");
curl_close ($ch);
$startposition = strpos($result,$start);
if($startposition > 0){
$endposition = strpos($result,$end, $startposition);
//add enough chars to include the tag
$endposition += strlen($end);
$length = $endposition-$startposition;
$result = substr($result,$startposition,$length);
echo $result;
}else
echo "Sorry Forecast Unavailable";
?>