Reputation: 849
We want to set the timezone up as a variable in PHP to account for different timezones / daylight savings.
Our code works perfectly when hard coded:
date_default_timezone_set('Australia/Brisbane');
But when we add a variable it dies. I am not sure why.
$setzone = "Australia/Brisbane";
date_default_timezone_set('".$setzone."');
Upvotes: 1
Views: 333
Reputation: 2989
Try this code:
$setzone = "Australia/Brisbane";
date_default_timezone_set("$setzone");
Upvotes: 0
Reputation: 12127
if you will add quote then variable behaving as string
for instance
$setzone = "Australia/Brisbane";
echo '".$setzone."';
Output :
".$string." //output as string not a variable value
So you need to remove quote when passing string into variable
date_default_timezone_set('".$setzone."');
to
date_default_timezone_set($setzone);
Upvotes: 6