doufa5001 2011-10-04 04:01
浏览 67
已采纳

在php脚本之间回显php变量

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条回答 默认 最新

  • dounao5856 2011-10-04 04:06
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?