...

View Full Version : Celcius for Simple MSN Weather



masey
02-12-2006, 09:31 PM
I wish to implement the Simple MSN Weather (http://www.gatequest.net/misc/php/msn-weather.php) PHP code to my website but I want the readout to be in Celcius rather than Farrenheit. Has anyone done this or know what I need to do to the following script to make it happen?


<?php

if (!$accid) {
$accid="USHI0026";
}

$url ="http://www.msnbc.com/m/chnk/d/weather_d_src.asp?acid=$accid";

# Use cURL to get the page
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$CurlContent = curl_exec ($ch);
curl_close ($ch);

# Look for fieldnames, set into $WeatherFields array
$FieldPattern = '|this.sw([^\s]+) = |';
preg_match_all($FieldPattern, $CurlContent, $WeatherFields);

# Parse data into hash
foreach ($WeatherFields[1] as $WeatherField) {
$FieldSpec = '|this.sw' . $WeatherField . ' = "([^\"]+)|';
preg_match($FieldSpec, $CurlContent, $WeatherData);
$MsnWeather[$WeatherField] = $WeatherData[1];
}

## DEBUG
## print_r($MsnWeather);

print "<table onmouseover=\"this.style.cursor='pointer'; return true;\" onmouseout=\"return true;\" onClick=\"top.location.href='http://weather.msn.com/local.aspx?wealocations=wc:USHI0026'\">";
print "<tr><td><img align=\"absmiddle\" border=\"0\" src=\"icons/". $MsnWeather['CIcon'] . ".gif\"> <strong>". $MsnWeather['Temp'] ."F </strong></td></tr></table>";

?>

goughy000
02-13-2006, 12:05 AM
I have added some conversion


$MsnWeather['Temp'] = $MsnWeather['Temp']-32;
$MsnWeather['Temp'] = $MsnWeather['Temp']/9;
$MsnWeather['Temp'] = $MsnWeather['Temp']*5;
$MsnWeather['Temp'] = round($MsnWeather['Temp'], 1);


So overall code is...


<?php

if (!$accid) {
$accid="USHI0026";
}

$url ="http://www.msnbc.com/m/chnk/d/weather_d_src.asp?acid=$accid";

# Use cURL to get the page
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$CurlContent = curl_exec ($ch);
curl_close ($ch);

# Look for fieldnames, set into $WeatherFields array
$FieldPattern = '|this.sw([^\s]+) = |';
preg_match_all($FieldPattern, $CurlContent, $WeatherFields);

# Parse data into hash
foreach ($WeatherFields[1] as $WeatherField) {
$FieldSpec = '|this.sw' . $WeatherField . ' = "([^\"]+)|';
preg_match($FieldSpec, $CurlContent, $WeatherData);
$MsnWeather[$WeatherField] = $WeatherData[1];
}

## DEBUG
## print_r($MsnWeather);

$MsnWeather['Temp'] = $MsnWeather['Temp']-32;
$MsnWeather['Temp'] = $MsnWeather['Temp']/9;
$MsnWeather['Temp'] = $MsnWeather['Temp']*5;
$MsnWeather['Temp'] = round($MsnWeather['Temp'], 1);

print "<table onmouseover=\"this.style.cursor='pointer'; return true;\" onmouseout=\"return true;\" onClick=\"top.location.href='http://weather.msn.com/local.aspx?wealocations=wc:USHI0026'\">";
print "<tr><td><img align=\"absmiddle\" border=\"0\" src=\"icons/". $MsnWeather['CIcon'] . ".gif\"> <strong>". $MsnWeather['Temp'] ."C </strong></td></tr></table>";

?>


Should work..

masey
02-13-2006, 03:32 AM
Thanks so much for that but I am getting values with a decimal. eg. 7.8C

It looks like you attempted to rectify this through this part of the code you added:


$MsnWeather['Temp'] = round($MsnWeather['Temp'], 1);

However, it doesn't seem to work.

What else needs to be done?

Thanks...

masey
02-14-2006, 02:11 AM
I worked it out... this is the fix:


$MsnWeather['Temp'] = round($MsnWeather['Temp'], 0);

Errica
02-14-2006, 03:08 PM
Cool script. Can I throw a wrench into it? :)

How would you combine the two so that you could display both fahrenheit and celcius?

StupidRalph
02-17-2006, 04:44 AM
First let me say that I'm quite jealous if you are in Honolulu :D.
But didn't the original script already correctly find Farrenheit? If so just save the farenheit temperature before its converted. Like this,


#Record the farenheit temperature.
$MsnWeather['FTemp'] = $MsnWeather['Temp'];

#Convert farenheit to celcius.
$MsnWeather['CTemp'] = $MsnWeather['Temp']-32;
$MsnWeather['CTemp'] = $MsnWeather['Temp']/9;
$MsnWeather['CTemp'] = $MsnWeather['Temp']*5;
$MsnWeather['CTemp'] = round($MsnWeather['Temp'], 0);






So overall code is...



<?php

if (!$accid) {
$accid="USHI0026";
}

$url ="http://www.msnbc.com/m/chnk/d/weather_d_src.asp?acid=$accid";

# Use cURL to get the page
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$CurlContent = curl_exec ($ch);
curl_close ($ch);

# Look for fieldnames, set into $WeatherFields array
$FieldPattern = '|this.sw([^\s]+) = |';
preg_match_all($FieldPattern, $CurlContent, $WeatherFields);

# Parse data into hash
foreach ($WeatherFields[1] as $WeatherField) {
$FieldSpec = '|this.sw' . $WeatherField . ' = "([^\"]+)|';
preg_match($FieldSpec, $CurlContent, $WeatherData);
$MsnWeather[$WeatherField] = $WeatherData[1];
}

## DEBUG
## print_r($MsnWeather);

#Record the farrenheit temperature.
$MsnWeather['FTemp'] = $MsnWeather['Temp'];

#Convert Farrenheit to Celcius.
$MsnWeather['CTemp'] = $MsnWeather['Temp']-32;
$MsnWeather['CTemp'] = $MsnWeather['Temp']/9;
$MsnWeather['CTemp'] = $MsnWeather['Temp']*5;
$MsnWeather['CTemp'] = round($MsnWeather['Temp'], 0);

print "<table onmouseover=\"this.style.cursor='pointer'; return true;\" onmouseout=\"return true;\" onClick=\"top.location.href='http://weather.msn.com/local.aspx?wealocations=wc:USHI0026'\"><tr><td><img align=\"absmiddle\" border=\"0\" src=\"icons/". $MsnWeather['CIcon'] . ".gif\"> <strong>". $MsnWeather['CTemp'] ."&#176;C </strong></td></tr><tr><td><img align=\"absmiddle\" border=\"0\" src=\"icons/". $MsnWeather['CIcon'] . ".gif\"> <strong>". $MsnWeather['FTemp'] ."&#176;F </strong></td></tr></table>";

?>


Whereever you want to use your Farrenheit temperature print $MsnWeather['FTemp'];.
I believe this should work, however don't quote me. I can't test this code. :D

goughy000
02-17-2006, 11:52 AM
However, it doesn't seem to work.


It works fine... it was meant to return it with a decimel :)

but you wanting it as a hole number, your fix will work fine...


Whereever you want to use your Farrenheit temperature print $MsnWeather['FTemp'];.
I believe this should work, however don't quote me. I can't test this code.

I've read through, all looks good but havn't tested it

Errica
02-20-2006, 08:28 PM
For some reason, the script is displaying farenheit for both...no celsius.

Thoughts?

masey
02-20-2006, 08:38 PM
I've also noticed that when MSN put out a "N/A" as the current condition you get a red cross "image not found" square as the icon. Anybody know what that is all about?

goughy000
02-20-2006, 08:40 PM
Problem seems to be...


#Convert Farrenheit to Celcius.
$MsnWeather['CTemp'] = $MsnWeather['Temp']-32;
$MsnWeather['CTemp'] = $MsnWeather['Temp']/9;
$MsnWeather['CTemp'] = $MsnWeather['Temp']*5;
$MsnWeather['CTemp'] = round($MsnWeather['CTemp'], 0);

Should be...


#Convert Farrenheit to Celcius.
$MsnWeather['CTemp'] = $MsnWeather['Temp']-32;
$MsnWeather['CTemp'] = $MsnWeather['CTemp']/9;
$MsnWeather['CTemp'] = $MsnWeather['CTemp']*5;
$MsnWeather['CTemp'] = round($MsnWeather['CTemp'], 0);

So overall code...

<?php

if (!$accid) {
$accid="USHI0026";
}

$url ="http://www.msnbc.com/m/chnk/d/weather_d_src.asp?acid=$accid";

# Use cURL to get the page
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$CurlContent = curl_exec ($ch);
curl_close ($ch);

# Look for fieldnames, set into $WeatherFields array
$FieldPattern = '|this.sw([^\s]+) = |';
preg_match_all($FieldPattern, $CurlContent, $WeatherFields);

# Parse data into hash
foreach ($WeatherFields[1] as $WeatherField) {
$FieldSpec = '|this.sw' . $WeatherField . ' = "([^\"]+)|';
preg_match($FieldSpec, $CurlContent, $WeatherData);
$MsnWeather[$WeatherField] = $WeatherData[1];
}

## DEBUG
## print_r($MsnWeather);

#Record the farrenheit temperature.
$MsnWeather['FTemp'] = $MsnWeather['Temp'];

#Convert Farrenheit to Celcius.
$MsnWeather['CTemp'] = $MsnWeather['Temp']-32;
$MsnWeather['CTemp'] = $MsnWeather['CTemp']/9;
$MsnWeather['CTemp'] = $MsnWeather['CTemp']*5;
$MsnWeather['CTemp'] = round($MsnWeather['CTemp'], 0);

print "<table onmouseover=\"this.style.cursor='pointer'; return true;\" onmouseout=\"return true;\" onClick=\"top.location.href='http://weather.msn.com/local.aspx?wealocations=wc:USHI0026'\"><tr><td><img align=\"absmiddle\" border=\"0\" src=\"icons/". $MsnWeather['CIcon'] . ".gif\"> <strong>". $MsnWeather['CTemp'] ."C </strong></td></tr><tr><td><img align=\"absmiddle\" border=\"0\" src=\"icons/". $MsnWeather['CIcon'] . ".gif\"> <strong>". $MsnWeather['FTemp'] ."F </strong></td></tr></table>";

?>

The mess up seems to come from StupidRalph's addittion to the code

goughy000
02-20-2006, 08:50 PM
I've also noticed that when MSN put out a "N/A" as the current condition you get a red cross "image not found" square as the icon. Anybody know what that is all about?

Give this a whizz.. added some checks to see if MSN weather has returned "N/A", if it has, dont print an img but print "N/A".


<?php

if (!$accid) {
$accid="USHI0026";
}

$url ="http://www.msnbc.com/m/chnk/d/weather_d_src.asp?acid=$accid";

# Use cURL to get the page
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$CurlContent = curl_exec ($ch);
curl_close ($ch);

# Look for fieldnames, set into $WeatherFields array
$FieldPattern = '|this.sw([^\s]+) = |';
preg_match_all($FieldPattern, $CurlContent, $WeatherFields);

# Parse data into hash
foreach ($WeatherFields[1] as $WeatherField) {
$FieldSpec = '|this.sw' . $WeatherField . ' = "([^\"]+)|';
preg_match($FieldSpec, $CurlContent, $WeatherData);
$MsnWeather[$WeatherField] = $WeatherData[1];
}


# If the temp is N/A...
if($MsnWeather[Temp] == "N/A"){
$notavailabletemp = "1";
}


#Record the farrenheit temperature.
$MsnWeather['FTemp'] = $MsnWeather['Temp'];

#Convert Farrenheit to Celcius.
if($notavailabletemp == 1){
$MsnWeather['CTemp'] = $MsnWeather['Temp'];
}else{
$MsnWeather['CTemp'] = $MsnWeather['Temp']-32;
$MsnWeather['CTemp'] = $MsnWeather['CTemp']/9;
$MsnWeather['CTemp'] = $MsnWeather['CTemp']*5;
$MsnWeather['CTemp'] = round($MsnWeather['CTemp'], 0);
}

print "<table onmouseover=\"this.style.cursor='pointer'; return true;\" onmouseout=\"return true;\" onClick=\"top.location.href='http://weather.msn.com/local.aspx?wealocations=wc:USHI0026'\"><tr><td>";

if($notavailabletemp == 1){
echo "N/A";
}else{
echo "<img align=\"absmiddle\" border=\"0\" src=\"icons/". $MsnWeather['CIcon'] . ".gif\">";
}

echo "<strong>". $MsnWeather['CTemp'] ."C </strong></td></tr><tr><td>";

if($notavailabletemp == 1){
echo "N/A";
}else{
echo "<img align=\"absmiddle\" border=\"0\" src=\"icons/". $MsnWeather['CIcon'] . ".gif\"> <strong>". $MsnWeather['FTemp'] ."F </strong></td></tr></table>";
}

?>

StupidRalph
02-20-2006, 08:59 PM
For some reason, the script is displaying farenheit for both...no celsius.

Thoughts?

Your not getting both? I just copied the above script and it returned both for me. The only problem I did have was on line 3 from the original code.


if (!$accid) {


was coming up undefined, it should be


if (!isset($accid) {


As far as the image....It doesn't show up in the first original code posted, alteast not for me. Therefore, my code isn't going to show it either. It is looking for the image in a relative path called (icons/30.gif) so if you don't have a folder named (icons) on your local machine with (30.gif) inside....you are going to get that error.

Also, I see that I am returning Undefined offset on line 21. :1
Is WeatherFields[1] and array? If not, then foreach has a valid reason to complain.

The only thing I did in my code was introduce a new variable to save the farenheit temperture before it is converted. However, I did forget to change the last few lines in the conversion from Weather[Temp] to Weather[CTemp] but Goughy took care of that already I typically do all my conversions on one line utilizing PEMDAS.


$num = 2; //num equals 2
$num2= $num; //num2 now equals 2
$num2 = ($num2 +1) * 3; //2 + 1 times 3 === num2 should now yield 9


However I did add a new <tr> with the would be Celcius temp just to show you how to print it out.

masey
02-20-2006, 09:00 PM
Can you change it so rather than printing "N/A" you get the following icon:

images/icons/44.gif

Which gives you: http://www.pacificsafaris.baremetal.com/images/icons/44.gif

StupidRalph
02-20-2006, 09:18 PM
I think we are working under different conditions. When I tried goughy's code. This is what I got (check view attachment). It returns both temp. But also a few errors. Are you guys not getting this?

StupidRalph
02-20-2006, 09:34 PM
If what goughy had worked for you...all you have to do is where goughy echoed out "N/A" print the img src for the icon like this.


<?php

if (!$accid) {
$accid="USHI0026";
}

$url ="http://www.msnbc.com/m/chnk/d/weather_d_src.asp?acid=$accid";

# Use cURL to get the page
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$CurlContent = curl_exec ($ch);
curl_close ($ch);

# Look for fieldnames, set into $WeatherFields array
$FieldPattern = '|this.sw([^\s]+) = |';
preg_match_all($FieldPattern, $CurlContent, $WeatherFields);

# Parse data into hash
foreach ($WeatherFields[1] as $WeatherField) {
$FieldSpec = '|this.sw' . $WeatherField . ' = "([^\"]+)|';
preg_match($FieldSpec, $CurlContent, $WeatherData);
$MsnWeather[$WeatherField] = $WeatherData[1];
}


# If the temp is N/A...
if($MsnWeather[Temp] == "N/A"){
$notavailabletemp = "1";
}


#Record the farrenheit temperature.
$MsnWeather['FTemp'] = $MsnWeather['Temp'];

#Convert Farrenheit to Celcius.
if($notavailabletemp == 1){
$MsnWeather['CTemp'] = $MsnWeather['Temp'];
}else{
$MsnWeather['CTemp'] = $MsnWeather['Temp']-32;
$MsnWeather['CTemp'] = $MsnWeather['CTemp']/9;
$MsnWeather['CTemp'] = $MsnWeather['CTemp']*5;
$MsnWeather['CTemp'] = round($MsnWeather['CTemp'], 0);
}

print "<table onmouseover=\"this.style.cursor='pointer'; return true;\" onmouseout=\"return true;\" onClick=\"top.location.href='http://weather.msn.com/local.aspx?wealocations=wc:USHI0026'\"><tr><td>";

if($notavailabletemp == 1){
echo "N/A";
}else{
echo "<img align=\"absmiddle\" border=\"0\" src=\"icons/". $MsnWeather['CIcon'] . ".gif\">";
}

echo "<strong>". $MsnWeather['CTemp'] ."C </strong></td></tr><tr><td>";

if($notavailabletemp == 1){
echo "<img src=\"icons/44.gif\">";
}else{
echo "<img align=\"absmiddle\" border=\"0\" src=\"icons/". $MsnWeather['CIcon'] . ".gif\"> <strong>". $MsnWeather['FTemp'] ."F </strong></td></tr></table>";
}

?>

masey
02-20-2006, 09:34 PM
As far as the image....It doesn't show up in the first original code posted, alteast not for me. Therefore, my code isn't going to show it either. It is looking for the image in a relative path called (icons/30.gif) so if you don't have a folder named (icons) on your local machine with (30.gif) inside....you are going to get that error.

You get the folder of images from HERE (http://www.gatequest.net/gqDownloads/download.php?get=GateQuest_weather_icons.zip&pname=GateQuest%20Weather%20Package)

masey
02-22-2006, 06:05 AM
OK... I'm still getting the ol' red cross when there's a N/A value. It's driving me nuts!!!

I'm currently using this code and I'm interested in a Celcius readout ONLY:


<?php

if (!$accid) {
$accid="CAXX0502";
}

$url ="http://www.msnbc.com/m/chnk/d/weather_d_src.asp?acid=$accid";

# Use cURL to get the page
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$CurlContent = curl_exec ($ch);
curl_close ($ch);

# Look for fieldnames, set into $WeatherFields array
$FieldPattern = '|this.sw([^\s]+) = |';
preg_match_all($FieldPattern, $CurlContent, $WeatherFields);

# Parse data into hash
foreach ($WeatherFields[1] as $WeatherField) {
$FieldSpec = '|this.sw' . $WeatherField . ' = "([^\"]+)|';
preg_match($FieldSpec, $CurlContent, $WeatherData);
$MsnWeather[$WeatherField] = $WeatherData[1];
}

# If the temp is N/A...
if($MsnWeather[Temp] == "N/A"){
$notavailabletemp = "1";
}

## DEBUG
## print_r($MsnWeather);

$MsnWeather['Temp'] = $MsnWeather['Temp']-32;
$MsnWeather['Temp'] = $MsnWeather['Temp']/9;
$MsnWeather['Temp'] = $MsnWeather['Temp']*5;
$MsnWeather['Temp'] = round($MsnWeather['Temp'], 0);

print "<table onmouseover=\"this.style.cursor='pointer'; return true;\" onmouseout=\"return true;\" onClick=\"top.location.href='http://weather.msn.com/local.aspx?wealocations=wc:CAXX0502'\">";

if($notavailabletemp == 1){
echo "<img src=\"../../images/icons/44.gif\">";
}else {
echo "<tr><td nowrap=\"nowrap\"><img align=\"absmiddle\" border=\"0\" src=\"../../images/icons/". $MsnWeather['CIcon'] . ".gif\"> <strong>". $MsnWeather['Temp'] ."&deg;C </strong></td></tr></table>";
}

?>

Can someone help me out here?

StupidRalph
02-22-2006, 07:22 AM
When you right click on the red x picture and view the properties.....what is the URL?

And what should it be?

masey
02-22-2006, 07:27 AM
It is:

http://www.pacificsafaris.baremetal.com/images/icons/.gif

and it should be:

http://www.pacificsafaris.baremetal.com/images/icons/44.gif

StupidRalph
02-22-2006, 07:33 AM
So we aren't getting a value for
$MsnWeather['CIcon']. Echo out $MsnWeather['CIcon'] and see if I am correct. I'll try your code and see what I get.

masey
02-22-2006, 07:37 AM
I'm not all that great with this whole coding stuff and pretty much missed what you just said about "echoing out" $MsnWeather['CIcon'] so I'm going to hang tight and see what you come up with.

Thanks for your help though - really appreciate it.

StupidRalph
02-22-2006, 07:52 AM
Place this line at the end of your script. This will print the value of CIcon....but I'm suspecting that $MsnWeather['CIcon'] isn't being set. Therefore it won't equal anything.


echo "MsnWeather['CIcon'] === " . $MsnWeather['CIcon'];

masey
02-22-2006, 07:58 AM
OK... this is now what the last part of my code looks like as per your suggestion, and it still doesn't work:


print "<table onmouseover=\"this.style.cursor='pointer'; return true;\" onmouseout=\"return true;\" onClick=\"top.location.href='http://weather.msn.com/local.aspx?wealocations=wc:CAXX0502'\">";

if($notavailabletemp == 1){
echo "<img src=\"../../images/icons/44.gif\">";
}
else {
echo "<tr><td nowrap=\"nowrap\"><img align=\"absmiddle\" border=\"0\" src=\"../../images/icons/". $MsnWeather['CIcon'] . ".gif\"> <strong>". $MsnWeather['Temp'] ."&deg;C </strong></td></tr></table>";
echo "MsnWeather['CIcon'] === " . $MsnWeather['CIcon'];
}

StupidRalph
02-22-2006, 08:11 AM
The echo function is used to OUTPUT to the browser window so we can visibly see the value of $Msnweather['CIcon']; When you run the script in your browser you should see


$Msnweather['CIcon'] === value

If that variable is receiving a value then it would print out here. If not, which is what I am suspecting then it will just say:

MsnWeather['CIcon'] ===
In that case we will have to find out why it isn't being set. PM your messenger name if you have one.

masey
02-22-2006, 10:04 AM
OK OK...

For those of you who need a 100% working script for use with Celcius ONLY, here's what Ralph and I have come up with after a bunch of collaboration tonight. I just want to thank him publicly for his efforts. Cracker job mate!

Here tis:


<?php

if (!$accid) {
$accid="USHI0026";
}

$url ="http://www.msnbc.com/m/chnk/d/weather_d_src.asp?acid=$accid";

# Use cURL to get the page
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$CurlContent = curl_exec ($ch);
curl_close ($ch);

# Look for fieldnames, set into $WeatherFields array
$FieldPattern = '|this.sw([^\s]+) = |';
preg_match_all($FieldPattern, $CurlContent, $WeatherFields);

# Parse data into hash
foreach ($WeatherFields[1] as $WeatherField) {
$FieldSpec = '|this.sw' . $WeatherField . ' = "([^\"]+)|';
preg_match($FieldSpec, $CurlContent, $WeatherData);
$MsnWeather[$WeatherField] = $WeatherData[1];
}

# If the temp is N/A...
if($MsnWeather[Temp] == "N/A"){
$notavailabletemp = "1";
}

## DEBUG
## print_r($MsnWeather);

$MsnWeather['Temp'] = $MsnWeather['Temp']-32;
$MsnWeather['Temp'] = $MsnWeather['Temp']/9;
$MsnWeather['Temp'] = $MsnWeather['Temp']*5;
$MsnWeather['Temp'] = round($MsnWeather['Temp'], 0);

print "<table onmouseover=\"this.style.cursor='pointer'; return true;\" onmouseout=\"return true;\" onClick=\"top.location.href='http://weather.msn.com/local.aspx?wealocations=wc:USHI0026'\">";
if ($MsnWeather['CIcon']=="" OR $MsnWeather['CIcon']=="NULL") {
$MsnWeather['CIcon'] = 44;
}
#echo "MsnWeather ===" . $MsnWeather['CIcon'];
echo "<tr><td nowrap=\"nowrap\"><img align=\"absmiddle\" border=\"0\" src=\"images/icons/". $MsnWeather['CIcon'] . ".gif\"> <strong>". $MsnWeather['Temp'] ."&deg;C </strong></td></tr></table>";


?>

Of course you will need to edit the images path to reflect the location of your folder containing the icons that you can get here (http://www.gatequest.net/gqDownloads/download.php?get=GateQuest_weather_icons.zip&pname=GateQuest%20Weather%20Package).

Cheers... :thumbsup:

StupidRalph
02-22-2006, 10:26 AM
Got rid of some of the unnecessary code. BTW masey did the work..I just watched. And be cautious of this script. The errors are turned off on his host. You might have to do some tweaks to it. SEE LINE 3.


<?php

if (!$accid) {
$accid="USHI0026";
}

$url ="http://www.msnbc.com/m/chnk/d/weather_d_src.asp?acid=$accid";

# Use cURL to get the page
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$CurlContent = curl_exec ($ch);
curl_close ($ch);

# Look for fieldnames, set into $WeatherFields array
$FieldPattern = '|this.sw([^\s]+) = |';
preg_match_all($FieldPattern, $CurlContent, $WeatherFields);

# Parse data into hash
foreach ($WeatherFields[1] as $WeatherField) {
$FieldSpec = '|this.sw' . $WeatherField . ' = "([^\"]+)|';
preg_match($FieldSpec, $CurlContent, $WeatherData);
$MsnWeather[$WeatherField] = $WeatherData[1];
}

## DEBUG
## print_r($MsnWeather);

#Convert Farrenheit to Celcius.
$MsnWeather['CTemp'] = round(((($MsnWeather['Temp']-32)/9)*5),0);

print "<table onmouseover=\"this.style.cursor='pointer'; return true;\" onmouseout=\"return true;\" onClick=\"top.location.href='http://weather.msn.com/local.aspx?wealocations=wc:USHI0026'\">";

#Set $MsnWeather['CIcon'] if empty or null
if ($MsnWeather['CIcon']=="" || $MsnWeather['CIcon']=="NULL") {
$MsnWeather['CIcon'] = 44;
}

echo "<tr><td nowrap=\"nowrap\"><img align=\"absmiddle\" border=\"0\" src=\"images/icons/". $MsnWeather['CIcon'] . ".gif\"> <strong>". $MsnWeather['Temp'] ."&deg;C </strong></td></tr></table>";

?>

ngohuynhnguyen
08-24-2007, 03:59 AM
this code is now no longer working because the source function from the source website is now retired



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum