public function getWeatherDataDigital($lat = '', $lon = '') { global $myPageNoaa1, $myCacheDir, $dateLongFormat, $timeFormat, $myDefaultIconsDir, $myDefaultIconsExt, $myDefaultIconsSml, $myNoaaIconsDir, $myNoaaIconsExt, $myNoaaIconsSml, $uomTemp, $uomWind, $uomRain, $uomSnow, $uomDistance; #---------------------------------------------------------------------------------------------- # clean user input #---------------------------------------------------------------------------------------------- $this->apiUrlpart[1] = round(trim($lat), 3); $this->apiUrlpart[3] = round(trim($lon), 3); #---------------------------------------------------------------------------------------------- # try loading data from cache #---------------------------------------------------------------------------------------------- if ($this->enableCache && !empty($this->cache)) { $this->cache = $myCacheDir; $uoms = $uomTemp . '-' . $uomWind . '-' . $uomRain . '-' . $uomSnow . '-' . $uomDistance; $string = $myPageNoaa1 . $this->apiUrlpart[1] . $this->apiUrlpart[3] . $uoms; $from = array('°', '∞', '/', ' ', '.'); $string = str_replace($from, '', $string); $this->cacheFile = $this->cache . $string . '.txt'; $returnArray = $this->loadFromCache(); // load from cache returns data only when its data is valid if (!empty($returnArray)) { return $returnArray; // if data is in cache and valid return data to calling program } // eo valid data, return to calling program } // eo check cache #---------------------------------------------------------------------------------------------- # combine everything into required url # http://forecast.weather.gov/MapClick.php?lat=41.3&lon=-72.78&FcstType=dwml #---------------------------------------------------------------------------------------------- $this->weatherApiUrl = ''; $end = count($this->apiUrlpart); for ($i = 0; $i < $end; $i++) { $this->weatherApiUrl .= $this->apiUrlpart[$i]; } #---------------------------------------------------------------------------------------------- ws_message('<!-- module noaaDigitalGenerateHtml.php (' . __LINE__ . '): loading from ' . $this->weatherApiUrl . ' -->'); if ($this->makeRequest()) { // load xml from url and process $this->rawData = str_replace('-name', '_name', $this->rawData); $xml = new SimpleXMLElement($this->rawData); if (!isset($xml->head->product->{'creation-date'})) { $string = substr($this->rawData, 0, 100); ws_message('Module ' . $myPageNoaa1 . ' (' . __LINE__ . '): Invalid data loaded for ' . $this->weatherApiUrl . '<br />First 100 chars of data loaded = ' . $string, true); return; } $returnArray = array(); $utcDiff = date('Z'); // to help to correct utc differences $string = (string) $xml->head->product->{'creation-date'}; $time = strtotime($string); $returnArray['information']['fileTimeStamp'] = strtotime($string); $returnArray['information']['fileTime'] = date('c', strtotime($string)); $returnArray['information']['updated'] = date($dateLongFormat, $time) . ' ' . date($timeFormat, $time); $returnArray['information']['location'] = (string) $xml->data->location->description . '-' . (string) $xml->data->location->point['latitude'] . '-' . (string) $xml->data->location->point['longitude']; $returnArray['information']['issued'] = (string) $xml->head->source->{'production-center'}; #-------------------------------------------------------------------------------------------------- # get forecast info #-------------------------------------------------------------------------------------------------- $arrTimes = array(); $endData = count($xml->data); $nData = 0; $endLayouts = count($xml->data[$nData]->{'time-layout'}); if ($endLayouts == 0) { echo '<h3> ' . $myPageNoaa1 . ' - invalid xml file - program halted </h3>'; exit; } for ($nLayouts = 0; $nLayouts < $endLayouts; $nLayouts++) { $forecast = $xml->data[$nData]->{'time-layout'}[$nLayouts]; $endTimes = count($forecast->{'start-valid-time'}); $layoutKey = (string) $forecast->{'layout-key'}; for ($nTimes = 0; $nTimes < $endTimes; $nTimes++) { $key = $layoutKey . '|' . $nTimes; $startTime = (string) $forecast->{'start-valid-time'}[$nTimes]; $daypart = (string) $forecast->{'start-valid-time'}[$nTimes]['period_name']; $arrTimes[$key]['startTime'] = $startTime; if ($daypart != '') { $arrTimes[$key]['daypart'] = $daypart; } $endTime = (string) $forecast->{'end-valid-time'}[$nTimes]; $arrTimes[$key]['endTime'] = $endTime; } // eof times } // eof layouts # echo '<pre>'; print_r ($arrTimes); exit; $result = array(); $endParameters = count($xml->data[$nData]->{'parameters'}); for ($nParameters = 0; $nParameters < $endParameters; $nParameters++) { $arr = $xml->data[$nData]->{'parameters'}[$nParameters]; $count = -1; foreach ($arr as $key => $value) { $count++; $name = (string) $key; $layout = (string) $value['time-layout']; if (isset($value['type'])) { $type = (string) $value['type']; } else { $type = ''; } if (isset($value['units'])) { $units = (string) $value['units']; } else { $units = ''; } $endValues = count($value->value); for ($nValues = 0; $nValues < $endValues; $nValues++) { $start = $arrTimes[$layout . '|' . $nValues]['startTime'] . '|' . $arrTimes[$layout . '|' . $nValues]['endTime']; #echo '<pre>'.$start.PHP_EOL; $result[$start][$name][$type] = array('units' => $units, 'value' => (string) $value->value[$nValues]); } // eo for evert parameter value if (isset($value->{'weather-conditions'})) { $endConds = count($value->{'weather-conditions'}); for ($nConds = 0; $nConds < $endConds; $nConds++) { $start = $arrTimes[$layout . '|' . $nConds]['startTime'] . '|' . $arrTimes[$layout . '|' . $nConds]['endTime']; // $condition = $value->{'weather-conditions'}[$nConds]; # echo '<pre>'; print_r($condition); exit; $endValues = count($condition->value); for ($nValues = 0; $nValues < $endValues; $nValues++) { $type = 'weather-conditions'; $weather = (string) $condition->value[$nValues]['weather-type']; // rain showers $units = (string) $condition->value[$nValues]['coverage']; // chance $extra = (string) $condition->value[$nValues]['additive']; // and $intensity = (string) $condition->value[$nValues]['intensity']; // light or non $qualifier = (string) $condition->value[$nValues]['qualifier']; // ?? none? $result[$start][$name][$type][$nValues] = array('units' => $units, 'intensity' => $intensity, 'value' => $weather, 'qualifier' => $qualifier, 'extra' => $extra); } // for every conditionvalue } // eo for every weather-conditions } // eo if weather-conditions if (isset($value->{'icon-link'})) { # echo '<pre>'; print_r($value->{'icon-link'}); print_r($value); exit; $endIcons = count($value->{'icon-link'}); for ($nIcons = 0; $nIcons < $endIcons; $nIcons++) { $start = $arrTimes[$layout . '|' . $nIcons]['startTime'] . '|' . $arrTimes[$layout . '|' . $nIcons]['endTime']; $icon = $value->{'conditions-icon'}[$nIcons]; $result[$start][$name][$type] = array('units' => 'url', 'value' => (string) $value->{'icon-link'}[$nIcons]); } // eo for every icon } // eo if conditions-icon } // eo foreach parameter values } // eo for every parameter ksort($result); # echo '<pre>'.PHP_EOL; print_r ($result); echo '</pre>'.PHP_EOL;# exit; $arrFcst = array(); $tempFound = $dewpFound = $appFound = $windFound = $gustFound = $winddirFound = $cloudsFound = $humFound = $txtFound = $rainFound = $snowFound = $popFound = false; foreach ($result as $key => $arr) { list($from, $to) = explode('|', $key); if ($to == '') { // new point forecast if (isset($arrFcst['to'])) { $returnArray['forecast'][] = $arrFcst; $arrFcst['liquid'] = $arrFcst['liquidNU'] = $arrFcst['snow'] = $arrFcst['snowNU'] = '-'; } else { $arrFcst['to'] = $arrFcst['from']; $arrFcst['toStamp'] = strtotime($arrFcst['from']); } $arrFcst['from'] = $arrFcst['to']; $arrFcst['fromStamp'] = strtotime($arrFcst['to']); $arrFcst['to'] = $from; $arrFcst['toStamp'] = strtotime($from); if (isset($arr['temperature']['hourly']['value'])) { $string = $arr['temperature']['hourly']['value']; $amount = round(noaaconvertemp($string, $this->uomTemp), 1); $arrFcst['temp'] = $amount . $uomTemp; $arrFcst['tempNU'] = $amount; $tempFound = true; } else { $arrFcst['temp'] = $arrFcst['tempNU'] = ''; } if (isset($arr['temperature']['dew point']['value'])) { $string = $arr['temperature']['dew point']['value']; $amount = round(noaaconvertemp($string, $this->uomTemp), 1); $arrFcst['dewp'] = $amount . $uomTemp; $arrFcst['dewpNU'] = $amount; $dewpFound = true; } else { $arrFcst['dew'] = $arrFcst['dewpNU'] = ''; } if (isset($arr['temperature']['apparent']['value'])) { $string = $arr['temperature']['apparent']['value']; $amount = round(noaaconvertemp($string, $this->uomTemp), 1); $arrFcst['tempApp'] = $amount . $uomTemp; $arrFcst['tempAppNU'] = $amount; $appFound = true; } else { $arrFcst['tempApp'] = $arrFcst['tempAppNU'] = ''; } if (isset($arr['wind-speed']['sustained']['value'])) { $string = $arr['wind-speed']['sustained']['value']; $arrbft = noaabeaufort($string, $this->uomWindSpeed); $arrFcst['beaufortnr'] = $arrbft[0]; $arrFcst['beaufortclr'] = $arrbft[1]; $arrFcst['beauforttxt'] = $arrbft[2]; $amount = round(noaaconvertwind($string, $this->uomWindSpeed)); $arrFcst['windSpeed'] = $amount . $uomWind; $arrFcst['windSpeedNU'] = $amount; $windFound = true; $arrFcst['windSpeedNU'] = $amount; } else { $arrFcst['windSpeed'] = $arrFcst['windSpeedNU'] = ''; } if (isset($arr['wind-speed']['gust']['value'])) { $string = $arr['wind-speed']['gust']['value']; $amount = round(noaaconvertwind($string, $this->uomWindSpeed)); $arrFcst['windGust'] = $amount . $uomWind; $arrFcst['windGustNU'] = $amount; $gustFound = true; } else { $arrFcst['windGust'] = $arrFcst['windGustNU'] = ''; } if (isset($arr['direction']['wind']['value'])) { $arrFcst['windDirDeg'] = $arr['direction']['wind']['value']; $string = noaaconvertwinddir($arrFcst['windDirDeg']); $arrFcst['windDirRose'] = $string; $from = array('North', 'East', 'South', 'West'); $to = array('N', 'E', 'S', 'W'); $arrFcst['windLbl'] = str_replace($from, $to, $string); $winddirFound = true; } else { $arrFcst['windDirDeg'] = $arrFcst['windLbl'] = $arrFcst['windDirRose'] = ''; } if (isset($arr['cloud-amount']['total']['value'])) { $arrFcst['clouds'] = $arr['cloud-amount']['total']['value']; $cloudsFound = true; } else { $arrFcst['clouds'] = ''; } if (isset($arr['humidity']['relative']['value'])) { $arrFcst['hum'] = $arr['humidity']['relative']['value'] . ' %'; $humFound = true; } else { $arrFcst['hum'] = ''; } if (isset($arr['conditions-icon']['forecast-NWS']['value'])) { $iconFound = true; $string = $arr['conditions-icon']['forecast-NWS']['value']; $arrFcst['iconUrl'] = $string; $arrUrl = explode('/', $string); $nr = count($arrUrl) - 1; list($icon, $ext) = explode('.', $arrUrl[$nr]); $arrFcst['icon'] = $icon; $from = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'); $inconIn = str_replace($from, '', $icon); $arrFcst['iconCleaned'] = $inconIn; $iconDefault = wsconvertnoaaicon($inconIn); $arrFcst['defailtIcon'] = $iconDefault; $arrFcst['defailtIconUrl'] = $myDefaultIconsDir . $iconDefault . '.' . $myDefaultIconsExt; $arrFcst['defailtIconSmlUrl'] = $myDefaultIconsSml . $iconDefault . '.' . $myDefaultIconsExt; $arrFcst['noaaIconUrl'] = $myNoaaIconsDir . $icon . '.' . $myNoaaIconsExt; $arrFcst['noaaIconSmlUrl'] = $myNoaaIconsSml . $icon . '.' . $myNoaaIconsExt; } else { $arrFcst['iconUrl'] = $arrFcst['iconDefault'] = $arrFcst['icon'] = ''; } $nr = 1.0 * $arrFcst['defailtIcon']; if ($nr < 101) { $string = 'no clouds'; } elseif ($nr < 201) { $string = 'some clouds'; } elseif ($nr < 301) { $string = 'partly cloudy'; } else { $string = 'overcast'; } $string = wsnoaafcttransstr($string); if (isset($arr['weather']['weather-conditions'])) { $endCond = count($arr['weather']['weather-conditions']); for ($i = 0; $i < $endCond; $i++) { $arrCond = $arr['weather']['weather-conditions'][$i]; # if ($arrCond['extra'] <> '') {$string .= '<br />'.wsnoaafcttransstr($arrCond['extra']);} if ($arrCond['units'] != '') { $string .= '<br />' . wsnoaafcttransstr($arrCond['units']) . ' '; } if ($arrCond['intensity'] != '' && $arrCond['intensity'] != 'none') { $string .= wsnoaafcttransstr($arrCond['intensity']) . ' '; } if ($arrCond['value'] != '') { $string .= wsnoaafcttransstr($arrCond['value']) . ' '; } if ($arrCond['qualifier'] != '' && $arrCond['qualifier'] != 'none') { $string .= wsnoaafcttransstr($arrCond['qualifier']) . ' '; } } $txtFound = true; } $arrFcst['weatherTxt'] = $string; continue; } else { if (!isset($arrFcst['from'])) { $arrFcst['from'] = $from; } } if (isset($arr['precipitation'])) { $arrFcst['liquid'] = $arrFcst['liquidNU'] = $arrFcst['snow'] = $arrFcst['snowNU'] = '-'; if (isset($arr['precipitation']['liquid'])) { $string = $arr['precipitation']['liquid']['value']; $amount = noaaconvertrain($string, $this->uomRain); $arrFcst['liquid'] = $amount . $uomRain; $arrFcst['liquidNU'] = $amount; $rainFound = true; } if (isset($arr['precipitation']['snow'])) { $string = $arr['precipitation']['snow']['value']; $amount = noaaconvertrain($string, $this->uomRain); $arrFcst['snow'] = $amount . $uomSnow; $arrFcst['snowNU'] = $amount; if ($amount != 0) { $snowFound = true; } } continue; } if (isset($arr['temperature'])) { $arrFcst['tempMax'] = $arrFcst['tempMin'] = ''; if (isset($arr['temperature']['maximum'])) { $string = $arr['temperature']['maximum']['value']; $amount = round(noaaconvertemp($string, $this->uomTemp)); $arrFcst['tempMax'] = $amount . $uomTemp; $arrFcst['tempMaxNU'] = $amount; } if (isset($arr['temperature']['minimum'])) { $string = $arr['temperature']['minimum']['value']; $amount = round(noaaconvertemp($string, $this->uomTemp)); $arrFcst['tempMin'] = $amount . $uomTemp; $arrFcst['tempMinNU'] = $amount; } } if (isset($arr['probability-of-precipitation'])) { $arrFcst['pop'] = $arr['probability-of-precipitation']['12 hour']['value']; $popFound = true; } } // eo for each $return $returnArray['forecast'][] = $arrFcst; $returnArray['information']['tempFound'] = $tempFound; $returnArray['information']['dewpFound'] = $dewpFound; $returnArray['information']['appFound'] = $appFound; $returnArray['information']['windFound'] = $windFound; $returnArray['information']['gustFound'] = $gustFound; $returnArray['information']['winddirFound'] = $winddirFound; $returnArray['information']['cloudsFound'] = $cloudsFound; $returnArray['information']['humFound'] = $humFound; $returnArray['information']['txtFound'] = $txtFound; $returnArray['information']['rainFound'] = $rainFound; $returnArray['information']['snowFound'] = $snowFound; $returnArray['information']['popFound'] = $popFound; $ret = $this->writeToCache($returnArray); return $returnArray; } else { echo '<h3>Loading data ' . $this->weatherApiUrl . ' failed </h3>' . PHP_EOL; } }
public function getWeatherData($lat = '', $lon = '') { global $dateLongFormat, $timeFormat, $myCacheDir, $myPageNoaa1, $uomTemp, $uomWind, $uomRain, $uomSnow, $uomDistance, $myNoaaIconsDir, $myNoaaIconsExt, $myDefaultIconsDir, $myDefaultIconsExt; #---------------------------------------------------------------------------------------------- # clean user input #---------------------------------------------------------------------------------------------- $this->apiUrlpart[1] = round(trim($lat), 3); $this->apiUrlpart[3] = round(trim($lon), 3); #---------------------------------------------------------------------------------------------- # try loading data from cache #---------------------------------------------------------------------------------------------- if ($this->enableCache && !empty($this->cache)) { $this->cache = $myCacheDir; $uoms = $uomTemp . '-' . $uomWind . '-' . $uomRain . '-' . $uomSnow . '-' . $uomDistance; $string = $myPageNoaa1 . $this->apiUrlpart[1] . $this->apiUrlpart[3] . $uoms; $from = array('°', '∞', '/', ' ', '.'); $string = str_replace($from, '', $string); $this->cacheFile = $this->cache . $string . '.txt'; $returnArray = $this->loadFromCache(); // load from cache returns data only when its data is valid if (!empty($returnArray)) { return $returnArray; // if data is in cache and valid return data to calling program } // eo valid data, return to calling program } // eo check cache #---------------------------------------------------------------------------------------------- # combine everything into required url # http://forecast.weather.gov/MapClick.php?lat=41.3&lon=-72.78&FcstType=dwml #---------------------------------------------------------------------------------------------- $this->weatherApiUrl = ''; $end = count($this->apiUrlpart); for ($i = 0; $i < $end; $i++) { $this->weatherApiUrl .= $this->apiUrlpart[$i]; } #---------------------------------------------------------------------------------------------- ws_message('<!-- module noaaPlainGenerateHtml.php (' . __LINE__ . '): loading from ' . $this->weatherApiUrl . ' -->'); if ($this->makeRequest()) { // load xml from url and process $this->rawData = str_replace('-name', '_name', $this->rawData); $xml = new SimpleXMLElement($this->rawData); # echo '<pre>'.PHP_EOL; # print_r ($xml); # echo 'test'; # var_dump( $xml->data[0]->{'time-layout'}[1]->{'start-valid-time'}[1]['period_name']); # echo (string) $xml->data[0]->{'time-layout'}[1]->{'start-valid-time'}[1]['period_name']; # exit; $returnArray = array(); $utcDiff = date('Z'); // to help to correct utc differences $string = (string) $xml->head->product->{'creation-date'}; $time = strtotime($string); $returnArray['information']['filetime'] = date('c', strtotime($string)); $returnArray['information']['updated'] = date($dateLongFormat, $time) . ' ' . date($timeFormat, $time); $returnArray['information']['location'] = (string) $xml->data[0]->location->description; if ($returnArray['information']['location'] == '') { $returnArray['information']['location'] = (string) $xml->data[0]->location->{'area-description'}; } $returnArray['information']['issued'] = (string) $xml->head->source->{'production-center'}; #-------------------------------------------------------------------------------------------------- # get forecast info #-------------------------------------------------------------------------------------------------- $i = 0; $returnArray['forecast'][$i]['dayPart'] = 'daypart'; // <start-valid-time period-name="Today $returnArray['forecast'][$i]['startTime'] = 'startTime'; // <start-valid-time period->2013-05-24T06:00:00-04:00</start-valid-time> $returnArray['forecast'][$i]['endTime'] = 'endTime'; // <end-valid-time>2013-05-30T18:00:00-04:00</end-valid-time> # <temperature type="maximum" units="Fahrenheit" time-layout="k-p24h-n7-1"><value>68</value> # <temperature type="minimum" units="Fahrenheit" time-layout="k-p24h-n6-2"><value>50</value> $returnArray['forecast'][$i]['tempMaxNU'] = 'temp'; $returnArray['forecast'][$i]['tempMax'] = 'temp'; $returnArray['forecast'][$i]['tempMinNU'] = 'temp'; $returnArray['forecast'][$i]['tempMin'] = 'temp'; # <probability-of-precipitation type="12 hour" units="percent" time-layout="k-p12h-n13-1"> $returnArray['forecast'][$i]['PoP'] = 'PoP'; # <weather time-layout="k-p12h-n13-1"><name>Weather Type, Coverage, Intensity</name><weather-conditions weather-summary="Showers"/> $returnArray['forecast'][$i]['weatherDescShort'] = 'condition'; // Showers $returnArray['forecast'][$i]['weatherDescText'] = 'condition Description'; // Showers and possibly a thunderstorm. High near 68. Southwest $returnArray['forecast'][$i]['icon'] = 'icon code'; // nra90 $returnArray['forecast'][$i]['iconUrl'] = 'icon Url'; // http://forecast.weather.gov/images/wtf/medium/ra80.png $endLayouts = count($xml->data[0]->{'time-layout'}); $arrTimes = array(); for ($nLayouts = 0; $nLayouts < $endLayouts; $nLayouts++) { $forecast = $xml->data[0]->{'time-layout'}[$nLayouts]; $endTimes = count($forecast->{'start-valid-time'}); $layoutKey = (string) $forecast->{'layout-key'}; for ($nTimes = 0; $nTimes < $endTimes; $nTimes++) { $key = $layoutKey . '|' . $nTimes; $startTime = (string) $forecast->{'start-valid-time'}[$nTimes]; $daypart = (string) $forecast->{'start-valid-time'}[$nTimes]['period_name']; $arrTimes[$key]['startTime'] = $startTime; if ($daypart != '') { $arrTimes[$key]['daypart'] = $daypart; } $endTime = (string) $forecast->{'end-valid-time'}[$nTimes]; if ($endTime != '') { $arrTimes[$key]['endTime'] = $endTime; } } // eof times } // eof layouts $endTemp = count($xml->data[0]->parameters->temperature); for ($nTemp = 0; $nTemp < $endTemp; $nTemp++) { $temps = $xml->data[0]->parameters->temperature[$nTemp]; # print_r($temps); $layoutKey = (string) $temps['time-layout']; $string = (string) $temps['type']; if ($string == 'maximum') { $valueKey = 'tempMax'; } else { $valueKey = 'tempMin'; } $string = (string) $temps['units']; $uomTemp = substr($string, 0, 1); $endValue = count($temps->value); # echo '$endValue '.$endValue ; exit; for ($nValue = 0; $nValue < $endValue; $nValue++) { $key = $layoutKey . '|' . $nValue; $string = (string) $temps->value[$nValue]; $value = round(noaaconvertemp($string, $uomTemp)); $arrTimes[$key][$valueKey . 'NU'] = $value; $arrTimes[$key][$valueKey] = $value . $uomTemp; } } $endPoP = count($xml->data[0]->parameters->{'probability-of-precipitation'}); for ($nPoP = 0; $nPoP < $endPoP; $nPoP++) { $PoPs = $xml->data[0]->parameters->{'probability-of-precipitation'}[$nPoP]; # print_r($PoPs); $layoutKey = (string) $PoPs['time-layout']; $valueKey = 'PoP'; $endValue = count($PoPs->value); # echo '$endValue '.$endValue ; exit; for ($nValue = 0; $nValue < $endValue; $nValue++) { $key = $layoutKey . '|' . $nValue; $arrTimes[$key][$valueKey] = (string) $PoPs->value[$nValue]; } } $endCondition = count($xml->data[0]->parameters->{'weather'}); for ($nCondition = 0; $nCondition < $endCondition; $nCondition++) { $Conditions = $xml->data[0]->parameters->{'weather'}[$nCondition]; # print_r($Conditions); $layoutKey = (string) $Conditions['time-layout']; $valueKey = 'weatherDescShort'; $endValue = count($Conditions->{'weather-conditions'}); # echo '$endValue '.$endValue ; exit; for ($nValue = 0; $nValue < $endValue; $nValue++) { $key = $layoutKey . '|' . $nValue; $value = (string) $Conditions->{'weather-conditions'}[$nValue]['weather-summary']; $arrTimes[$key][$valueKey] = $value; } } $endIcon = count($xml->data[0]->parameters->{'conditions-icon'}); for ($nIcon = 0; $nIcon < $endIcon; $nIcon++) { $Icons = $xml->data[0]->parameters->{'conditions-icon'}[$nIcon]; # print_r($Icons); $layoutKey = (string) $Icons['time-layout']; $valueKey = 'iconUrl'; $endValue = count($Icons->{'icon-link'}); # echo '$endValue '.$endValue ; exit; for ($nValue = 0; $nValue < $endValue; $nValue++) { $key = $layoutKey . '|' . $nValue; $value = (string) $Icons->{'icon-link'}[$nValue]; $arrTimes[$key][$valueKey] = $value; } } $endhazards = count($xml->data[0]->parameters->{'hazards'}); $returnArray['information']['hazards'] = $endhazards; for ($nhazards = 0; $nhazards < $endhazards; $nhazards++) { $hazards = $xml->data[0]->parameters->{'hazards'}[$nhazards]; # print_r($hazards); $layoutKey = (string) $hazards['time-layout']; $endValue = count($hazards->{'hazard-conditions'}->hazard); # echo '$endValue '.$endValue ; exit; for ($nValue = 0; $nValue < $endValue; $nValue++) { $key = $layoutKey . '|' . $nValue; $string = (string) $hazards->{'hazard-conditions'}->hazard[$nValue]->hazardTextURL; $arrTimes[$key]['hazardUrl'] = str_replace('&', '&', $string); $arrTimes[$key]['hazardType'] = (string) $hazards->{'hazard-conditions'}->hazard[$nValue]['headline']; } } $endWord = count($xml->data[0]->parameters->{'wordedForecast'}); for ($nWord = 0; $nWord < $endWord; $nWord++) { $Words = $xml->data[0]->parameters->{'wordedForecast'}[$nWord]; # print_r($Words); $layoutKey = (string) $Words['time-layout']; $valueKey = 'weatherDescText'; $endValue = count($Words->{'text'}); # echo '$endValue '.$endValue ; exit; for ($nValue = 0; $nValue < $endValue; $nValue++) { $key = $layoutKey . '|' . $nValue; $value = (string) $Words->{'text'}[$nValue]; $arrTimes[$key][$valueKey] = $value; } } # echo '<pre>'.PHP_EOL; print_r ($arrTimes); exit; foreach ($arrTimes as $key => $arr) { if (!isset($arr['hazardType'])) { $type = 'forecast'; $start = $arr['startTime']; } else { $type = 'hazard'; $start = $arr['hazardType']; if ($start == '') { continue; } } # $returnArray[$type][$start]['startTime']=$start; /* <hazardTextURL>http://forecast.weather.gov/showsigwx.php?warnzone=NVZ037&warncounty=NVC011&firewxzone=NVZ454&local_place1=6+Miles+NNW+Eureka+NV&product1=Red+Flag+Warning</hazardTextURL> */ foreach ($arr as $keyValue => $value) { # echo $keyValue.' - '.$value.PHP_EOL; # if ($keyValue == 'startTime') {continue;} $returnArray[$type][$start][$keyValue] = $value; } } foreach ($returnArray['forecast'] as $key => $arr) { if (!isset($arr['PoP']) || !isset($arr['iconUrl']) || $key == 0) { continue; } $remove = $arr['PoP']; $arrparts = explode('/', $arr['iconUrl']); // http://forecast.weather.gov/DualImage.php?i=shra&j=tsra&ip=30&jp=60 $location = count($arrparts) - 1; // http://forecast.weather.gov/newimages/medium/shra30.png $value = $arrparts[$location]; if (substr($value, 0, 13) == 'DualImage.php') { $rest = substr($value, 16); $arr_icon = explode('&', $rest); $icon = $arr_icon[0]; } else { $iconPoP = $none = ''; list($iconPoP, $none) = explode('.', $value); $icon = str_replace($remove, '', $iconPoP); } $defaulticon = wsconvertnoaaicon($icon); $returnArray['forecast'][$key]['noaaIcon'] = $icon; $returnArray['forecast'][$key]['defaultIcon'] = $defaulticon; # $returnArray['forecast'][$key]['noaaIconurl'] = $myNoaaIconsDir. $iconPoP.'.'. $myNoaaIconsExt; $returnArray['forecast'][$key]['noaaIconurl'] = htmlspecialchars($arr['iconUrl']); $returnArray['forecast'][$key]['defaultIconurl'] = $myDefaultIconsDir . $defaulticon . '.' . $myDefaultIconsExt; } # echo '<pre>'.PHP_EOL; print_r ($returnArray); exit; $ret = $this->writeToCache($returnArray); return $returnArray; } // eo makeRequest processing }