WXforum.net
Web Weather => Weather Web Site Help => Topic started by: anchorageweather on October 06, 2006, 11:48:21 AM
-
In the following code:
<?php
if (isset($_REQUEST['month'])) { $mon = $_REQUEST['month']; }
if (isset($_REQUEST['year'])) { $year = $_REQUEST['year']; }
if (isset($_REQUEST['day'])) { $day = $_REQUEST['day']; }
//Set the Timezone
putenv("TZ=US/Eastern");
$now = getdate();
// set the day/month/year to current if not passed as parms
if(!$mon) { $mon = $now['mon'];}
if(!$year) { $year = $now['year'];}
if(!$day) { $day = $now['mday'];}
$html = implode('', file('http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=KKYLOUIS20&year=2006&month=10&day=3'));
preg_match('|<thead>(.*)<table id="full" cellspacing="0" cellpadding="10">|s', $html, $betweenspan);
$dailytab = $betweenspan[1];
?>
<?echo $dailytab?>
Can anyone tell me the proper syntax to get the implode statement to accept dynamic date info from the isset info (days, months, years)? The code works perfectly if I set the date (as in the example above) but I can't get the syntax correct to add $mon, $day , $year in the implode statement :(
-
Sure..
Change the implode statement from $html = implode('', file('http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=KKYLOUIS20&year=2006&month=10&day=3'));
to
$html = implode('', file('http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=KKYLOUIS20&year=' . $year . '&month=' . $mon . '&day=' . $day));
Enclosing strings with single quote chars tells PHP not to parse the string for substituted variable names. Enclosing them in double quotes allows the variables within to be parsed. Example:
$string = 'parsed';
$a = '$string';
$b = "$string";
$a above with have the contents '$string'. $b above will have the contents 'parsed';
Ken
-
Thanks for the lesson - it worked like a charm :)