Help with a parsing a weather feed
Posted: Mon Aug 29, 2005 4:48 pm
I have this code below to parse a weather service feed. I get a unclosed token error. I'm wondering what I'm doing wrong. Any hlep would be greatly appreciated.
feyd | Please use
Code: Select all
<?php
$file = "http://xml.customweather.com/xml?client=havensclub_test&client_password=t3mp&product=expanded_forecast&id=70317&metric=true";
$depth = array();
$wd = array(); //weekday
$ht = array(); //high temp
$lt = array(); //low temp
$ic = array(); //icon
if (!($fp = fopen($file, "r"))) {
die("could not open XML input");
}
$p = xml_parser_create();
while ($data = fread($fp, 8192)) {
if (!xml_parse_into_struct($p, $data, $vals, $index)) {
die(sprintf("XMLnew error: %s at line %d",
xml_error_string(xml_get_error_code($p)),
xml_get_current_line_number($p)));
}
xml_parser_free($p);
/*
echo "<br>";
echo "Index array:\n";
print_r($index);
echo "<br>";
echo "\nVals array:\n";
print_r($vals);
echo "<br>";
*/
$wd[0] = $vals[2]["attributes"]["WEEKDAY"];
$wd[1] = $vals[4]["attributes"]["WEEKDAY"];
$wd[2] = $vals[6]["attributes"]["WEEKDAY"];
$ht[0] = round($vals[2]["attributes"]["HIGH_TEMP"]);
$ht[1] = round($vals[4]["attributes"]["HIGH_TEMP"]);
$ht[2] = round($vals[6]["attributes"]["HIGH_TEMP"]);
$lt[0] = round($vals[2]["attributes"]["LOW_TEMP"]);
$lt[1] = round($vals[4]["attributes"]["LOW_TEMP"]);
$lt[2] = round($vals[6]["attributes"]["LOW_TEMP"]);
$ic[0] = "images/weather/" . $vals[2]["attributes"]["ICON"] . ".gif";
$ic[1] = "images/weather/" . $vals[4]["attributes"]["ICON"] . ".gif";
$ic[2] = "images/weather/" . $vals[6]["attributes"]["ICON"] . ".gif";
}
xml_parser_free($xml_parser);
?>feyd | Please use
Code: Select all
andCode: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]