<?php
function left_time($end_date){
$unix_timestamp=strtotime($end_date);
$date = $unix_timestamp-time();
$day = $date/60/60/24;
$days = (int)$day;
$hour = $date/60/60 - $days*24;
$hours = (int)$hour;
$minute = $date/60 - $days*24*60 - $hours*60;
$minutes = (int)$minute;
$second = $date - $days*24*60*60 - $hours*60*60 - $minutes*60;
$seconds = (int)$second;
$result = array($days,$hours,$minutes,$seconds);
if($seconds>0){
return $result;
}else{
return 0;
}
}
$end_date="2010-11-3";
$left_time=left_time($end_date);
if(is_array($left_time)){
foreach($left_time as $key=>$value){
if($key==0){
echo $value."天";
}elseif($key==1){
echo $value."时";
}elseif($key==2){
echo $value."分";
}elseif($key==3){
echo $value."秒";
}
}
}
?>