1

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
date_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?

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

-1

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']);

1 Comment

This basically is the same as the answer Wasim Karani gave. Countdown uses 5 variables and passing one string, SESSION or VARIABLE, with all 5 elements will not work. This is due to it seeing it as only one variable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.