For the past few weeks I have been working on a type of CMS that does not need MySQL or any date base for that matter. :)

I am still new to php so this has been my helping hand in getting to learn a little. I am now on V2 of what I am calling Proclarush. (Yes I am a Stargate fan) And after setting up all the files and getting things to link rite I am now adding in some plugins. The one that was a pain to find was one for weather.

So lets get in to adding some weather to you site!

How I am doing this is by calling a .php file in to my site like this.

<?php include_once ('weather.php'); ? >

You can add that where ever you want your weather to show up.
**If you are new, make sure you are working with a .php file “index.php”**

Now to the code in side the weather.php I am going to put it all in at once and then help you out with how it works the best I can.

<div id="weather">
<h2 class="h2"> Weather </h2>
<?php
$weatherZIPCODE = "89145"; //Change The Zip HERE

function retrieveYahooWeather($zipCode = '$weatherZIPCODE') {
$yahooUrl = "http://weather.yahooapis.com/forecastrss";
$yahooZip = "?p=$zipCode";
$yahooFullUrl = $yahooUrl . $yahooZip;
$curlObject = curl_init();
curl_setopt($curlObject,CURLOPT_URL,$yahooFullUrl);
curl_setopt($curlObject,CURLOPT_HEADER,false);
curl_setopt($curlObject,CURLOPT_RETURNTRANSFER,true);
$returnYahooWeather = curl_exec($curlObject);
curl_close($curlObject);
return $returnYahooWeather;
}
$localZipCode = $weatherZIPCODE;
$weatherXmlString = retrieveYahooWeather($localZipCode);
$weatherXmlObject = new SimpleXMLElement($weatherXmlString);
$currentCondition = $weatherXmlObject->xpath("//yweather:condition");
$weatherLoca = $weatherXmlObject->xpath("//yweather:location");
$currentTemperature = $currentCondition[0]["temp"];
$currentDescription = $currentCondition[0]["text"];
$currentTitle = $currentTitle[0]["text"];
$weatherLoca = $weatherLoca[0]["city"];
?>
<ul>
<li> <?php print $weatherLoca;?></li>
<li>Current Temperature: <?php print $currentTemperature;?>°F</li>
<li>Current Description: <?php print $currentDescription;?></li>
</ul>
</div>

You can see it working
here
And download the files
here

Now to some of the need to know stuff.

This is just saying get the file “weather.php”

<?php include_once ('weather.php'); ? >

In weather.php look at line 4 and you will see where you set you zip code.
$weatherZIPCODE = "89145";

Now to get this to show the town I wanted I had to add this.

//Make This Up //Find this is the RSS
$weatherLoca = $weatherXmlObject->xpath("//yweather:location");
//This says it = its self but is looking in ["city"]
$weatherLoca = $weatherLoca[0]["city"];
//This Will Print it out :)
print $weatherLoca;

If you go to Yahoo Weather
you will be able to find the the xlm file that the php uses to get your information.
And it looks a lot like this

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<rss version="2.0" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
<channel>
<title>Yahoo! Weather - Sunnyvale, CA</title>
<link>http://us.rd.yahoo.com/dailynews/rss/weather/Sunnyvale__CA/*http://weather.yahoo.com/forecast/USCA1116_f.html</link>
<description>Yahoo! Weather for Sunnyvale, CA</description>
<language>en-us</language>
<lastBuildDate>Fri, 18 Dec 2009 9:38 am PST</lastBuildDate>
<ttl>60</ttl>
<yweather:location city="Sunnyvale" region="CA" country="United States"/>
<yweather:units temperature="F" distance="mi" pressure="in" speed="mph"/>
<yweather:wind chill="50" direction="0" speed="0" />
<yweather:atmosphere humidity="94" visibility="3" pressure="30.27" rising="1" />
<yweather:astronomy sunrise="7:17 am" sunset="4:52 pm"/>
<image>
<title>Yahoo! Weather</title>
<width>142</width>
<height>18</height>
<link>http://weather.yahoo.com</link>
<url>http://l.yimg.com/a/i/us/nws/th/main_142b.gif</url>
</image>
<item>
<title>Conditions for Sunnyvale, CA at 9:38 am PST</title>
<geo:lat>37.37</geo:lat>
<geo:long>-122.04</geo:long>
<link>http://us.rd.yahoo.com/dailynews/rss/weather/Sunnyvale__CA/*http://weather.yahoo.com/forecast/USCA1116_f.html</link>
<pubDate>Fri, 18 Dec 2009 9:38 am PST</pubDate>
<yweather:condition text="Mostly Cloudy" code="28" temp="50" date="Fri, 18 Dec 2009 9:38 am PST" />
<description><![CDATA[
<img src="http://l.yimg.com/a/i/us/we/52/28.gif"/><br />
<b>Current Conditions:</b><br />
Mostly Cloudy, 50 F<BR />
<BR /><b>Forecast:</b><BR />
Fri - Partly Cloudy. High: 62 Low: 49<br />
Sat - Partly Cloudy. High: 65 Low: 49<br />
<br />
<a href="http://us.rd.yahoo.com/dailynews/rss/weather/Sunnyvale__CA/*http://weather.yahoo.com/forecast/USCA1116_f.html">Full Forecast at Yahoo! Weather</a><BR/><BR/>
(provided by <a href="http://www.weather.com" >The Weather Channel</a>)<br/>
]]></description>
<yweather:forecast day="Fri" date="18 Dec 2009" low="49" high="62" text="Partly Cloudy" code="30" />
<yweather:forecast day="Sat" date="19 Dec 2009" low="49" high="65" text="Partly Cloudy" code="30" />
<guid isPermaLink="false">USCA1116_2009_12_18_9_38_PST</guid>
</item>
</channel>
</rss>

If you are like me your thinking what the hell is that! But after looking at it for a little bit its not that hard.

Watch.
Say you want to add in the wind chill.
Look for the line that says “yweather:wind”
And create a line that looks like this

$Thisisthewindchill = $weatherXmlObject->xpath("//yweather:wind");

There you are making a Variable “$Thisisthewindchill” and saying in equal to the yahoo xml file and in “yweather:wind”

Now make a line that looks like this.

$Thisisthewindchill = $Thisisthewindchill [0]["chill"];

There you are saying “$Thisisthewindchill” equals its self but is to look in “chill”.

Now all you have to do is add this line to UL/LI

print $Thisisthewindchill ;

As I said I am newish to php so I might have got something wrong, or worded something the wrong way. So if you see some thing let me know and I will change it. But I know this works and can help if you need any help setting it up on your site. Just leave a comment and I will get back to you asap!

Again you can download it
here!