?
Solved

XML/PHP Weather from Weather.com - Problem

Posted on 2005-03-21
2
Medium Priority
?
364 Views
Last Modified: 2012-05-05
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>";
###################################################################################
?>
0
Comment
Question by:gregca80
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Author Comment

by:gregca80
ID: 13596598
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
 
LVL 8

Accepted Solution

by:
_Marcel_ earned 500 total points
ID: 13602137
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question