Thursday, 22 August 2013

Case/Switch using Strings

Case/Switch using Strings

I have this weather script that and I'm trying to display a different
image for every weather condition (case), the image will also be different
if it's day or night.
Here is what I'm doing...
GETTING THE XML Info. into .PHP
<?php
$CapDCityANDState = "Atlanta, GA";
$url="https://www.google.com/ig/api?weather=$CapDCityANDState&hl=en&referrer=googlecalendar";
$xml = simplexml_load_file($url);
//print_r($xml);
//echo "Test: " . $xml->current_conditions->temp_f['data'];
$DayNow = date(D);
$DayTomorrow = date('D', strtotime('+1 day'));
$DayAfterTomorrow = date('D', strtotime('+2 day'));
$DayAfterAfterTomorrow = date('D', strtotime('+3 day'));
$CurrentTxt =
$xml->weather->current_conditions->condition->attributes()->data;
$CurrentTemp =
$xml->weather->current_conditions->temp_f->attributes()->data;
//echo $CurrentTemp[0];
echo("<BR><BR>");
$DayOneLow =
$xml->weather->forecast_conditions[0]->low->attributes()->data;
$DayOneHi =
$xml->weather->forecast_conditions[0]->high->attributes()->data;
$DayOneTxt =
$xml->weather->forecast_conditions[0]->condition->attributes()->data;
//echo $DayOneLow[0];
$DayTwoLow =
$xml->weather->forecast_conditions[1]->low->attributes()->data;
$DayTwoHi =
$xml->weather->forecast_conditions[1]->high->attributes()->data;
$DayTwoTxt =
$xml->weather->forecast_conditions[1]->condition->attributes()->data;
//echo $DayTwoLow[0];
$DayTriLow =
$xml->weather->forecast_conditions[2]->low->attributes()->data;
$DayTriHi =
$xml->weather->forecast_conditions[2]->high->attributes()->data;
$DayTriTxt =
$xml->weather->forecast_conditions[2]->condition->attributes()->data;
//echo $DayTriLow[0];
$DayFourLow =
$xml->weather->forecast_conditions[3]->low->attributes()->data;
$DayFourHi =
$xml->weather->forecast_conditions[3]->high->attributes()->data;
$DayFourTxt =
$xml->weather->forecast_conditions[3]->condition->attributes()->data;
//echo $DayFourLow[0];
?>
DISPLAY WEATHER FORCAST INFO.
<div>Currently: <?php echo $CurrentTemp[0]; ?>&deg; - <?php echo
$CurrentTxt[0]; ?> - H: <?php echo $DayOneHi[0]; ?>&deg; L: <?php echo
$DayOneLow[0]; ?>&deg; - Rest of the Day: <?php echo $DayOneTxt[0];
?></div>
<div><?php echo($DayTomorrow);?>: <?php echo $DayTwoHi[0];
?>&deg;/<?php echo $DayTwoLow[0]; ?>&deg; - <?php echo
$DayTwoTxt[0]; ?></div>
<div><?php echo($DayAfterTomorrow);?>: <?php echo
$DayTriHi[0]; ?>&deg;/<?php echo $DayTriLow[0]; ?>&deg; -
<?php echo $DayTriTxt[0]; ?></div>
<div><?php echo($DayAfterAfterTomorrow);?>: <?php echo
$DayFourHi[0]; ?>&deg;/<?php echo $DayFourLow[0]; ?>&deg; -
<?php echo $DayFourTxt[0]; ?></div>
<br>
FINDOUT IS IT DAY OR NITE CURRENTLY
<?php
$img = time() > $sunriseTime && time() < $sunsetTime ? 'day' : 'nite';
// $img <-- will say 'day' if it's day and 'nite' if its nite
?>
GET WHAT IMAGE TO SHOW DEPENDING IF IT'S DAY OR NITE AND ALSO GET THE
WEATHER CONDITION TEXT AND BASE THE IMAGE ON THOSE TWO FACTORS.
SHOW WHAT IMAGE NAME TO USE e.g. "32.png"
<?php echo($WeatherIMG); ?>
The image always shows "1.png" and that is wrong :(

No comments:

Post a Comment