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>
$weatherZIPCODE = "89145"; //Change The Zip HERE

function retrieveYahooWeather($zipCode = '$weatherZIPCODE') {
$yahooUrl = "";
$yahooZip = "?p=$zipCode";
$yahooFullUrl = $yahooUrl . $yahooZip;
$curlObject = curl_init();
$returnYahooWeather = curl_exec($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"];
<li> <?php print $weatherLoca;?></li>
<li>Current Temperature: <?php print $currentTemperature;?>°F</li>
<li>Current Description: <?php print $currentDescription;?></li>

You can see it working
And download the files

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="" xmlns:geo="">
<title>Yahoo! Weather - Sunnyvale, CA</title>
<description>Yahoo! Weather for Sunnyvale, CA</description>
<lastBuildDate>Fri, 18 Dec 2009 9:38 am PST</lastBuildDate>
<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"/>
<title>Yahoo! Weather</title>
<title>Conditions for Sunnyvale, CA at 9:38 am PST</title>
<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" />
<img src=""/><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="*">Full Forecast at Yahoo! Weather</a><BR/><BR/>
(provided by <a href="" >The Weather Channel</a>)<br/>
<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>

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.

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