connect('localhost', 11211); $cache_key = 'weather_zip_'.$zip_code; $cache_data = $cache->get($cache_key); if ($cache_data) { // There's a cache hit, nothing left to do. echo $cache_data; } else { // Get weather.com state code include_once( $USE_DATA ? 'database.php' : 'state_list.php' ); // Fetch raw data from weather.com $request_url1 = 'http://wxdata.weather.com/wxdata/obs_hirad/'.$state_code.'.xml?key=47ff9b4c-91d5-11e0-b754-001c23d537c5&units=m&locale='.$_GET['locale'].''; $xml1 = simplexml_load_file($request_url1); $request_url2 = 'http://wxdata.weather.com/wxdata/df/'.$state_code.'.xml?key=47ff9b4c-91d5-11e0-b754-001c23d537c5&day=1,2,3,4,5,6&units=m&locale='.$_GET['locale'].''; $xml2 = simplexml_load_file($request_url2, NULL, LIBXML_NOCDATA); $request_url3 = 'http://wxdata.weather.com/wxdata/loc/'.$state_code.'.xml?key=47ff9b4c-91d5-11e0-b754-001c23d537c5&locale='.$_GET['locale'].''; $xml3 = simplexml_load_file($request_url3, NULL, LIBXML_NOCDATA); // Extract relevant data $forecast1 = $xml2->xpath("/forecasts/forecast"); $forecast2 = $xml2->xpath("/forecasts/forecast/day"); $current = $xml1->xpath("/observation"); $name = $xml3->xpath("/location"); // Record date & time date_default_timezone_set($name[0]->zoneInfo) ; $fecha = $xml1->xpath("/weatherdata/weather/current"); $dia= date('d', time() + 0); $mes= date('m', time() + 0); $año= date('Y', time() + 0); $Hora= date('H:i',time() + 0); // If the cache is active, record output so we can store it if ($cache_connected) ob_start(); // Generate the output ?> {"weatherinfo":{ "sktq" : "maxTemp ?>\u00b0/minTemp ?>", "temp1" : "temp ?>\u00b0", "temp2" : "maxTemp ?>\u00b0/minTemp ?>\u00b0", "temp3" : "maxTemp ?>\u00b0/minTemp ?>\u00b0", "temp4" : "maxTemp ?>\u00b0/minTemp ?>\u00b0", "temp5" : "maxTemp ?>\u00b0/minTemp ?>\u00b0", "temp6" : "maxTemp ?>\u00b0/minTemp ?>\u00b0", "weather1" : "text ?>", "weather2" : "phrase ?>", "weather3" : "phrase ?>", "weather4" : "phrase ?>", "weather5" : "phrase ?>", "weather6" : "phrase ?>", "wind1" : "wSpeed ?> kph wDirText ?>", "wind2" : "wSpeed ?> kph wDirText ?>", "wind3" : "wSpeed ?> kph wDirText ?>", "wind4" : "wSpeed ?> kph wDirText ?>", "wind5" : "wSpeed ?> kph wDirText ?>", "wind6" : "wSpeed ?> kph wDirText ?>", "pressure" : "pressureDescription?>", "uvText" : "uvText?>", "humid" : "humid?>%", "visibility": "visibility?> km", "cityid" : "", "city_en" : "name ?>", "city" : "name ?>, ", "date_y" : "\u5e74\u6708\u65e5", "sktime" : "", "pubtime" : "-- "}} set($cache_key, $cache_data, 0, 10); $cache->close(); } } ?>