WXforum.net

Web Weather => Weather Web Site Help => Topic started by: anchorageweather on October 06, 2006, 11:48:21 AM

Title: a syntax question for PHP
Post by: anchorageweather on October 06, 2006, 11:48:21 AM
In the following code:
Code: [Select]
<?php 

if &#40;isset&#40;$_REQUEST['month'&#93;&#41;&#41; &#123; $mon = $_REQUEST['month'&#93;; &#125; 
if &#40;isset&#40;$_REQUEST['year'&#93;&#41;&#41; &#123; $year = $_REQUEST['year'&#93;; &#125; 
if &#40;isset&#40;$_REQUEST['day'&#93;&#41;&#41; &#123; $day = $_REQUEST['day'&#93;; &#125; 

     //Set the Timezone 
 
putenv&#40;"TZ=US/Eastern"&#41;; 
   
$now getdate&#40;&#41;; 
// set the day/month/year to current if not passed as parms 
if&#40;!$mon&#41; &#123; $mon = $now['mon'&#93;;&#125; 
if&#40;!$year&#41; &#123; $year = $now['year'&#93;;&#125; 
if&#40;!$day&#41;  &#123; $day  = $now['mday'&#93;;&#125; 


$html implode&#40;'', file&#40;'http&#58;//www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=KKYLOUIS20&year=2006&month=10&day=3'&#41;&#41;;

      
preg_match&#40;'|<thead>&#40;.*&#41;<table id="full" cellspacing="0" cellpadding="10">|s', $html, $betweenspan&#41;; 
      
$dailytab  $betweenspan[1&#93;; 

?>


<?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  :(
Title: a syntax question for PHP
Post by: saratogaWX on October 06, 2006, 01:18:25 PM
Sure..

Change the implode statement from
Code: [Select]
$html = implode('', file('http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=KKYLOUIS20&year=2006&month=10&day=3'));



to

Code: [Select]
$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:
Code: [Select]

$string = 'parsed';
$a = '$string';
$b = "$string";

$a above with have the contents '$string'.  $b above will have the contents 'parsed';

Ken
Title: a syntax question for PHP
Post by: anchorageweather on October 06, 2006, 02:08:37 PM
Thanks for the lesson - it worked like a charm :)