<p> This script is designed to read the xml wind feed from the <a href="http://piertopier.net" target=_"blank">piertopier.net</a> wind sensor.
Can be used to display the wind speed direction and strength of the last gust on any php based page.</p>
<h3>USAGE</h3>
<p>Needs no inputs, the address for the xml feeds at the top if it ever needs changing.<br>
The out put is in the form of three variables. $speed, $ direction and $gust. they are a numbers corresponding to the wind speed, wind direction and strength of he strongest gust received in the preceding 5 minutes. In knots and degrees.</p>

<h3>CODE</h3>
<div class="code">
<?php<br>
            //
Piertopier.net xml wind feed script<br>
            //
opens a connection for piertopier.net's xmlfeed, rips it<br>
up and returns:<br>
            //
$speed as the current wind speed in knots, $direction is<br>
a bearing in degrees, $gust is the strenght of the last gust in knots.<br>
// opens connection to pieritopier for current xml feed of wind speed.                                                       <br>
$host = 'www.piertopier.net';<br>
$uri = 'weather.xml';<br>
            $fp
= fsockopen($host, 80, $errno, $errstr, 20);<br>
                        if
(!$fp) {<br>
                                    die("Network
error: $errstr ($errno)");<br>
                        }
else {<br>
                                                $xml
= '';<br>
                                                fputs($fp, "GET
/$uri HTTP/1.0\r\nHost: $host\r\n\r\n");<br>
                                                while
(!feof($fp)) {<br>
                                                $xml
.= fgets($fp, 128);<br>
                                                                                                            }<br>
                                                fclose
($fp);<br>
                                                }<br>
// clears out unwanted sections from the XML feed.<br>
$search = array ("'HTTP[^>]*?>.*?knots='si", // Strip out everyting
up to wind speed<br>
                  "'mph[^>]*?>.*?knots='si", // Strip out everything between windspeed
and gust speed<br>
                  "'mph[^>]*?>.*?degrees='si", // Strip out every hting between
gust speed and direction<br>
                  "'</wind>[^>]*?>.*?rtList>'si", // strip out everyhting
after direction<br>
                  "'/>'i"); // Strips out irritating left over /> that I can't
figure<br>
$replace = array ("", //replace all the above with nothing!<br>
                  "",<br>
                  "",<br>
                  "",<br>
                  "",<br>
                  "",<br>
                  "",<br>
                  "",<br>
                 	"");<br>
            $xml
= preg_replace ($search, $replace, $xml);<br>
// stip out the Quotation Marks<br>
            $xml
= ereg_replace('"', "", $xml);<br>
// chops the xml feed up and stuffs it in an array<br>
            $pieces
= explode(" ", $xml);<br>
// gets the right cunks of the array and asigns them to variables for
display<br>
called speed direction and gust <br>
            $speed
= $pieces[0];<br>
            $direction
= $pieces[2];<br>
            $gust
= $pieces[1];<br>
</div>
