WXforum.net
June 19, 2013, 11:24:57 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
Members: 6697  •  Posts: 181450  •  Topics: 18423
Please welcome ThePontificator, our newest member.
Welcome to the the new hosting for WXforum.net.
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: a syntax question for PHP  (Read 2549 times)
0 Members and 1 Guest are viewing this topic.
anchorageweather
Forecaster
*****
Offline Offline

Posts: 445



WWW
« on: October 06, 2006, 11:48:21 AM »

In the following code:
Code:
<?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  Sad
Logged

South of the Tracks, Anchorage, KY
saratogaWX
Administrator
Forecaster
*****
Online Online

Posts: 3784


Saratoga, CA, USA Weather - free PHP scripts


WWW
« Reply #1 on: October 06, 2006, 01:18:25 PM »

Sure..

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



to

Code:
$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:

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

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

Ken
Logged

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
anchorageweather
Forecaster
*****
Offline Offline

Posts: 445



WWW
« Reply #2 on: October 06, 2006, 02:08:37 PM »

Thanks for the lesson - it worked like a charm Smile
Logged

South of the Tracks, Anchorage, KY
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 1.182 seconds with 18 queries.
anything