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条)

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看