I was given a script with different variables that are based on date and time on the top of XHTML Strict page.
<?php
date_default_timezone_set('America/Los_Angeles');
$time = new DateTime();
if($time < new DateTime('2011-10-31 18:00')){
$title="Before Halloween";
$cb1="2011,10,31,18,0";
}else if
...
?>
Halfway through the HTML code I have a second PHP script:
<?php
dat开发者_运维知识库e_default_timezone_set('America/Los_Angeles');
countdown(2011,10,31,18,0);
function countdown($year, $month, $day, $hour, $minute)
{
...
?>
How can I echo $cb1
from the upper script into the second script so the third line looks something like countdown(echo $cb1); and updates automatically based on the upper script?
Since it is a string you will need to explode (take apart) at the comma, to create 5 variables. To do this you would use:
$cbarray = explode(",",$cb1);
countdown($cbarray[0],$cbarray[1],$cbarray[2],$cbarray[3],$cbarray[4]);
Or something simalar by putting each one in a named variable.
You could try to set $cb1 as a session variable instead so you can access it from anywhere in the file.
Maybe replace:
$cb1="2011,10,31,18,0";
with
$_SESSION['cb1']="2011,10,31,18,0";
And then your code in the second script would be: countdown($_SESSION['cb1']);
精彩评论