XML/PHP Weather from Weather.com - Problem

Hello:

My goal is to pull weather data from weather.com and display it on my webpage with PHP. Two things to note are that the web server is currently IIS (don't know if this is the problem) and I'm using PHP 5.

I downloaded a php script from this website:

http://arsla.epn.ba/index.php?option=com_content&task=view&id=12&Itemid=57

The program consists of the index.php file, a folder with images, a config page (which is just the source url listed below), and a xmllib.php file.

It pulls some XML from this source:
http://xoap.weather.com/weather/local/USNV0049?cc=*&dayf=3&prod=xoap&par=[1007597404]&key=[2364083a1adf89b8]

When I run the index.php file I get these errors:

Example 1:

Notice: Use of undefined constant weather - assumed 'weather' in c:\Inetpub\wwwroot\test\weather\index.php on line 30

Notice: Use of undefined constant dayf - assumed 'dayf' in c:\Inetpub\wwwroot\test\weather\index.php on line 30

Notice: Use of undefined constant day - assumed 'day' in c:\Inetpub\wwwroot\test\weather\index.php on line 30

Notice: Use of undefined constant part - assumed 'part' in c:\Inetpub\wwwroot\test\weather\index.php on line 30

Notice: Use of undefined constant icon - assumed 'icon' in c:\Inetpub\wwwroot\test\weather\index.php on line 30


Any help or idea what may be wrong would be appreciated! Unfortunately I don't know much about XML, so I thought I'd turn to the experts. Thank you.


Here is what the index.php file looks like:

<?php
###################################################################################
#
# Weather report 1.1 index.php, by Aid Arslanagic, version 0.1
# http://arsla.epn.ba
#
# This code is released under The GNU General Public License (GPL).
# Read the license at http://www.opensource.org/licenses/gpl-license.php
#
###################################################################################
require ("inc/config.php");

$handle = fopen($query, 'r');
$xml = '';
while (!feof($handle)) {
  $xml.= fread($handle, 8192);
}
fclose($handle);
$data = XML_unserialize($xml);

###################################################################################
# Change the layout for your site below
###################################################################################

###################################################################################
# DAY 0
###################################################################################
echo "<TABLE border=0><TR><TD>Example 1:</TD><T/R><TR><TD>";
echo "<IMG SRC='icons/" . $data[weather][dayf][day][0][part][0][icon] . ".png'>";
echo "</TD></TR>";
echo "<TR><TD>";
echo "It's " . strtolower($data[weather][cc][t]) . " today in " . $data[weather][loc][dnam] . ".";
echo "</TD></TR><TR><TD><HR size=1></TD></TR>";
echo "</TABLE>";

###################################################################################
# DAY 1
###################################################################################
echo "<TABLE border=0><TR><TD>Example 2:</TD><T/R><TR><TD>";
echo "<IMG SRC='icons/" . $data[weather][dayf][day][1][part][0][icon] . ".png'>";
echo "</TD></TR>";
echo "<TR><TD>";
echo "It will be between " . $data[weather][dayf][day][1][low] . "°" . $data[weather][head][ut] . " and "  . $data[weather][dayf][day][1][hi] . "°" . $data[weather][head][ut] . " in " . $data[weather][loc][dnam] . " tomorrow.";
echo "</TD></TR><TR><TD><HR size=1></TD></TR>";
echo "</TABLE>";

###################################################################################
# DAY 2
###################################################################################
echo "<TABLE border=0><TR><TD>Example 3:</TD><T/R><TR><TD>";
echo "<IMG SRC='icons/" . $data[weather][dayf][day][2][part][0][icon] . ".png'>";
echo "</TD></TR>";
echo "<TR><TD>";
echo "It will be between " . $data[weather][dayf][day][2][low] . "°" . $data[weather][head][ut] . " and "  . $data[weather][dayf][day][2][hi] . "°" . $data[weather][head][ut] . " in " . $data[weather][loc][dnam] . " the day after tomorrow.";
echo "</TD></TR><TR><TD><HR size=1></TD></TR>";
echo "</TABLE>";

###################################################################################
# DAY 9
###################################################################################
echo "<TABLE border=0><TR><TD>Example 4:</TD><T/R><TR><TD>";
echo "<IMG SRC='icons/" . $data[weather][dayf][day][9][part][0][icon] . ".png'>";
echo "</TD></TR>";
echo "<TR><TD>";
echo "On " . $data[weather][dayf][day]["9 attr"][dt] . ", it will be between " . $data[weather][dayf][day][9][low] . "°" . $data[weather][head][ut] . " and "  . $data[weather][dayf][day][9][hi] . "°" . $data[weather][head][ut] . " in " . $data[weather][loc][dnam] . ".";
echo "</TD></TR><TR><TD><HR size=1></TD></TR>";
echo "</TABLE>";

###################################################################################
# Uncomment this to see complete array:
#
echo "<pre>";
print_r($data);
echo "</pre>";
###################################################################################
?>
gregca80Asked:
Who is Participating?
 
_Marcel_Connect With a Mentor Commented:
The notices you see are generated because the associated arrays used are not 'quoted'. You should use $myarray['myfield'], not $myarray[myfield]. In the latter case, the constant myfield is used as fieldname (but it isn't defined). PHP will use the word 'myfield' for you, but generate a notice.
To turn off the notices fix all the problems (but this might be quite cumbersome), or change your php.ini to not show notices. This may also be unwanted for other scripts, so you may want to just change it for this script (at the first line or something):

error_reporting(E_ALL ^ E_NOTICE);

0
 
gregca80Author Commented:
Just another comment... $query is the source URL of:

http://xoap.weather.com/weather/local/USNV0049?cc=*&dayf=3∏=xoap&par=[1007597404]&key=[2364083a1adf89b8]
0
All Courses

From novice to tech pro — start learning today.