format('Y-m-d') . '&API_KEY=CEA1E3AD-8816-4B77-8877-FF803214BDE9'; $current_api_url = 'http://www.airnowapi.org/aq/observation/zipCode/current/?format=application/xml&zipCode= 43215&API_KEY=CEA1E3AD-8816-4B77-8877-FF803214BDE9'; file_put_contents('current_airquality_cache.xml', file_get_contents($current_api_url)); file_put_contents('forecast_airquality_cache.xml', file_get_contents($forecast_api_url)); } //Check if empty $current_xml_content = trim(file_get_contents($current_xml_url)); $forecast_xml_content = trim(file_get_contents($forecast_xml_url)); if($current_xml_content == ''){ //Set to valid XML if it is $current_xml = simplexml_load_string('No data'); }else{ $current_xml = simplexml_load_file($current_xml_url); } if($forecast_xml_content == ''){ $forecast_xml = simplexml_load_string('No data'); }else{ $forecast_xml = simplexml_load_file($forecast_xml_url); } //Check if current weather exists if($current_xml->ObsByZip->count()){ $current_aqi = $current_xml->ObsByZip[0]->AQI; $current_cat_num = $current_xml->ObsByZip[0]->CategoryNumber; $current_cat_name = $current_xml->ObsByZip[0]->CategoryName; $current_aqi_particles = $current_xml->ObsByZip[1]->AQI; $current_cat_num_particles = $current_xml->ObsByZip[1]->CategoryNumber; $current_cat_name_particles = $current_xml->ObsByZip[1]->CategoryName; $current_available = true; } else{ $current_available = false; } //Check if forecast exists if($forecast_xml->ForecastByZip->count()){ $forecast_aqi = $forecast_xml->ForecastByZip[0]->AQI; $forecast_cat_num = $forecast_xml->ForecastByZip[0]->CategoryNumber; $forecast_cat_name = $forecast_xml->ForecastByZip[0]->CategoryName; $forecast_available = true; }else{ $forecast_available = false; } if($forecast_xml->ForecastByZip->count() > 1){ $forecast_aqi_particles = $forecast_xml->ForecastByZip[1]->AQI; $forecast_cat_num_particles = $forecast_xml->ForecastByZip[1]->CategoryNumber; $forecast_cat_name_particles = $forecast_xml->ForecastByZip[1]->CategoryName; } ?>
Current Air Quality
Metro Birmingham
$current_aqi) {?>

(PM2.5)
format('m\/d'); ?> Forecast:
$forecast_aqi) { ?> $forecast_aqi_particles) { ?> Coming Soon Coming Soon'; } ?>