Author Topic: a syntax question for PHP  (Read 2738 times)

0 Members and 1 Guest are viewing this topic.

Offline anchorageweather

  • Forecaster
  • *****
  • Posts: 445
    • http://eetee.us/station/station.php
a syntax question for PHP
« 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  :(
South of the Tracks, Anchorage, KY

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 4526
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
a syntax question for PHP
« Reply #1 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
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis Vantage Pro Plus - FARS, Boltek-PCI/NexStorm, GRLevel3, WD, WL, VWS, Cumulus, Meteohub
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline anchorageweather

  • Forecaster
  • *****
  • Posts: 445
    • http://eetee.us/station/station.php
a syntax question for PHP
« Reply #2 on: October 06, 2006, 02:08:37 PM »
Thanks for the lesson - it worked like a charm :)
South of the Tracks, Anchorage, KY