$day) { if($day['CATEGORY'] == 'Current Conditions') { $items[] = $day['TITLE']; } else { $items[] = $day['TITLE'].': '.$day['DESCRIPTION']; } } //print_r($items);die; //for debugging $output = ' '.$zip.' weather http://www.rssweather.com/zipcode/'.$zip.'/wx.php 60 rssWeather.com (http://www.rssweather.com/) en'; foreach($items as $item) { $output .= ''.$item.''; } $output .= ''; echo $output; /* Support Functions */ function XMLtoArray($XML) { $xml_parser = xml_parser_create(); xml_parse_into_struct($xml_parser, $XML, $vals); xml_parser_free($xml_parser); // wyznaczamy tablice z powtarzajacymi sie tagami na tym samym poziomie $_tmp=''; foreach ($vals as $xml_elem) { $x_tag=$xml_elem['tag']; $x_level=$xml_elem['level']; $x_type=$xml_elem['type']; if ($x_level!=1 && $x_type == 'close') { if (isset($multi_key[$x_tag][$x_level])) $multi_key[$x_tag][$x_level]=1; else $multi_key[$x_tag][$x_level]=0; } if ($x_level!=1 && $x_type == 'complete') { if ($_tmp==$x_tag) $multi_key[$x_tag][$x_level]=1; $_tmp=$x_tag; } } // jedziemy po tablicy foreach ($vals as $xml_elem) { $x_tag=$xml_elem['tag']; $x_level=$xml_elem['level']; $x_type=$xml_elem['type']; if ($x_type == 'open') $level[$x_level] = $x_tag; $start_level = 1; $php_stmt = '$xml_array'; if ($x_type=='close' && $x_level!=1) $multi_key[$x_tag][$x_level]++; while ($start_level < $x_level) { $php_stmt .= '[$level['.$start_level.']]'; if (isset($multi_key[$level[$start_level]][$start_level]) && $multi_key[$level[$start_level]][$start_level]) $php_stmt .= '['.($multi_key[$level[$start_level]][$start_level]-1).']'; $start_level++; } $add=''; if (isset($multi_key[$x_tag][$x_level]) && $multi_key[$x_tag][$x_level] && ($x_type=='open' || $x_type=='complete')) { if (!isset($multi_key2[$x_tag][$x_level])) $multi_key2[$x_tag][$x_level]=0; else $multi_key2[$x_tag][$x_level]++; $add='['.$multi_key2[$x_tag][$x_level].']'; } if (isset($xml_elem['value']) && trim($xml_elem['value'])!='' && !array_key_exists('attributes', $xml_elem)) { if ($x_type == 'open') $php_stmt_main=$php_stmt.'[$x_type]'.$add.'[\'content\'] = $xml_elem[\'value\'];'; else $php_stmt_main=$php_stmt.'[$x_tag]'.$add.' = $xml_elem[\'value\'];'; eval($php_stmt_main); } if (array_key_exists('attributes', $xml_elem)) { if (isset($xml_elem['value'])) { $php_stmt_main=$php_stmt.'[$x_tag]'.$add.'[\'content\'] = $xml_elem[\'value\'];'; eval($php_stmt_main); } foreach ($xml_elem['attributes'] as $key=>$value) { $php_stmt_att=$php_stmt.'[$x_tag]'.$add.'[$key] = $value;'; eval($php_stmt_att); } } } return $xml_array; } function cache_me_if_you_can($cachefile, $url, $expires_in_hours) { $current_time = time(); //get current unix timestamp $expire_time = $expires_in_hours * 60 * 60; //convert hours to seconds, because unix timestamp $file_time = file_exists($cachefile) ? filemtime($cachefile) : $current_time; //get the timestamp on the existing cached file if there is one //check the cache file to see if it's still valid, and if it is, send it back to the code that called this function if(file_exists($cachefile) && ($current_time - $expire_time < $file_time)) { return file_get_contents($cachefile); } else { //we need to cache a new copy // Some sites will reject a request if no User-Agent string is set. Tell them we're using Chrome. $context = stream_context_create(array( 'http'=>array( 'user_agent' => 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11' ) )); // Get data as a string if($content = file_get_contents($url, FALSE, $context)) { //create a new cache file file_put_contents($cachefile,$content); } else { //if we couldn't fetch a new copy, revert to the cache $expire_time = 4 * 60 * 60; //we don't want the cache to live indefinitely. Limit it to four hours. $file_time = file_exists($cachefile) ? filemtime($cachefile) : $current_time; if(file_exists($cachefile) && ($current_time - $expire_time < $file_time)) { return file_get_contents($cachefile); } else { return false; } } //return the new copy return $content; } } ?>