<p>Parses the Shipping Forecast, and retrieves only a specific area. + optionally the header "Issued by the Met Office at ****.</p>

<p>WARNING NOT TO BE USED FOR NAVIGATION. this is a gimmick and no substitute for a Properly sourced forecast. it may expire if any of several servers expire. Use for interest only. Also actually using it on a public site may be illegal I can find no sign saying you may not republish the shipping Forecast, it used to be a public service that bitch maggie( small m please take offence) probably privatised it. Am still annoyed about the unavailability of Brighton Tide Harmonics for the same reason!</p>
<h3>Description</h3>
<p><div class="code">get_forcast ( string sea area, int header, string format)</div></p>
<p>This is a PHP function that loads the shipping forecast from http://iwin.nws.noaa.gov  retrieves the currently published forecast for the are supplied, with or with out the intro and issue time (Issued by the Met office at "time" "date"). In 3 formats HTML (just p and br tags), text (unix linefeeds) or as a string (no linefeeds).</P>
<h3>Parameter List</h3>
    <p><div class="code">area</div></p>
<p>the forecast area you interested in in my case I put in "Dover". case insensitive (I hope).</p>
    <p><div class="code">header</div></p>
<p>Do you want the intro I strongly suggest you do, so you can tell its a current forecast that's being displayed. 0 (zero) for intro 1 for an intro</p>
<p><div class="code">format</div></p>
<p>Format, stick in one of the following:
<li>"text" nice dull text with unix line feed character (slash n).<br />
<li>"html" a paragraph of HTML with HTML linefeed markers (br)<br />
<li>"string" Dull boring no line feed text for further processing<br />
Return Values</p>
<p>Returns nice paragraph or string similar to:<br>
THE SHIPPING FORECAST ISSUED BY THE MET OFFICE AT 1725 ON SATURDAY 05 FEBRUARY 2005<br />
DOVER WIGHT PORTLAND SOUTH BACKING SOUTHEAST 3 OR 4, OCCASIONALLY 5. RAIN AT TIMES. MODERATE OR GOOD</P>
<h3>Example 1. get_forcast() example</h3>
<p><div class="code">
  echo get_forcast(Malin, 1, html);</p>
 </div>
<h3>The above will output:</h3>
<p><div class="code">THE SHIPPING FORECAST ISSUED BY THE MET OFFICE AT 1725 ON SATURDAY 05 FEBRUARY 2005</p>
SHANNON ROCKALL MALIN HEBRIDES NORTH 6 TO GALE 8, VEERING NORTHEAST 4 OR 5, OCCASIONALLY 6, BUT SOUTH OR SOUTHEAST IN NORTH ROCKALL AND HEBRIDES. SHOWERS. MODERATE OR GOOD</p>
</div>
<h3>CODE:</h3>
<div class="code"><p>function get_forcast($area, $header, $format) {<br>
//$header=0; $format="text"; $area="dover";<br>
// opens connection to get the shipping forecast&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp; $host = 'iwin.nws.noaa.gov';<br>
&nbsp;&nbsp;&nbsp;&nbsp; $uri = '/pub/data/text/FPUK71/EGRR.TXT';<br>
&nbsp;&nbsp;&nbsp;&nbsp; $fp = fsockopen($host, 80, $errno, $errstr, 20);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (!$fp) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;die("Network error: $errstr ($errno)");<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $all = '';<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fputs($fp, "GET /$uri HTTP/1.0\r\nHost: $host\r\n\r\n");<br>
&nbsp;&nbsp;&nbsp;&nbsp; while (!feof($fp)) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$all .= fgets($fp, 128);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;&nbsp;&nbsp; fclose ($fp);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>
<br>
$bits=explode("\n\r", $all);<br>
foreach($bits as $chunk)<br>
{<br>
if (preg_match("/$area/i", $chunk)) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;$out=$chunk;<br>
}<br>
if (preg_match("/ISSUED BY THE MET OFFICE/i", $chunk)) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;$head=$chunk;<br>
}<br>
}<br>
//clear up the header<br>
&nbsp;&nbsp;&nbsp;&nbsp; $head=preg_replace("/^FPUK71.*/m", "", $head);<br>
&nbsp;&nbsp;&nbsp;&nbsp; $head=preg_replace("/AND NOW /i", "", $head);<br>
&nbsp;&nbsp;&nbsp;&nbsp; $head=preg_replace("/, ON BEHALF OF\s*THE MARITIME AND COASTGUARD AGENCY,/si", "", $head);<br>
&nbsp;&nbsp;&nbsp;&nbsp; $head=preg_replace("/\s/", " ", $head);<br>
&nbsp;&nbsp;&nbsp;&nbsp; $head=preg_replace("/&nbsp;&nbsp;/", " ", $head);<br>
&nbsp;&nbsp;&nbsp;&nbsp; $head=preg_replace("/&nbsp;&nbsp;/", " ", $head);<br>
&nbsp;&nbsp;&nbsp;&nbsp; $head=trim($head);<br>
&nbsp;&nbsp;&nbsp;&nbsp; $head=($head."\n");<br>
//clear up the body<br>
&nbsp;&nbsp;&nbsp;&nbsp; $out=preg_replace("/\s/", " ", $out);<br>
&nbsp;&nbsp;&nbsp;&nbsp; $out=preg_replace("/&nbsp;&nbsp;/", " ", $out);<br>
&nbsp;&nbsp;&nbsp;&nbsp; $out=preg_replace("/&nbsp;&nbsp;/", " ", $out);<br>
&nbsp;&nbsp;&nbsp;&nbsp; $out=trim($out);<br>
&nbsp;&nbsp;&nbsp;&nbsp; $out=($out."\n");<br>
//decide whether the title's needed<br>
&nbsp;&nbsp;&nbsp;&nbsp; if(!$header=="0") $out=($head.$out);<br>
//do the formating<br>
&nbsp;&nbsp;&nbsp;&nbsp; switch($format){<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case($format=="html"): <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //formats output with <br> fo direct HTML Display.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $return=nl2br($out);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case($format=="string"):<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //formats the output as one linefeedless string.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $return=$preg_replace("/\s/s", "", $out);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$return=preg_replace("/&nbsp;&nbsp;/", " ", $return);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$return=preg_replace("/&nbsp;&nbsp;/", " ", $return);<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case($format=="text"):<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //formats the output as is with line feeds.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $return=$out;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>
//function completer output:&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp; return("$return"); <br>
<br>
}</p></div>