date_parse()在PHP 5.4中导致非法的字符串偏移量

时间:2013-02-25 01:20:12

标签: php

我一直在研究这个问题,但看不出我收到错误的原因。该警告引用了以下行:if ($i==$break_date['month'])并且仅在升级到PHP 5.4之后仍然存在

以下是动态生成日期选择器的非常有用的功能。任何见解都会非常感激。

function date_picker($name, $date, $startyear='2005', $endyear='2020') {  

$break_date = date_parse($date);


if($startyear==NULL) $startyear = date("Y")-100;
if($endyear==NULL) $endyear=date("Y")+50; 

$months=array('','01 January','02 February','03 March','04 April','05 May',
'06 June','07 July','08 August', '09 September','10 October','11 November','12 December');

// Month dropdown
$html="<select name=\"".$name."_month\" style='width: 22%;'>";
$html.="<option value=''>Month</option>";
for($i=1;$i<=12;$i++)
{
   if ($i==$break_date['month']) 
   { 
     $month_selected = "selected";
    } else {
     $month_selected = "";
   }
   $html.="<option value='$i' $month_selected>$months[$i]</option>";
}
$html.="</select> ";

// Day dropdown
$html.="<select name=\"".$name."_day\" style='width: 22%;'>";
$html.="<option value=''>Day</option>";    
for($i=1;$i<=31;$i++)
{
   if ($i==$break_date['day']) 
   { 
     $day_selected = "selected";
    } else {
     $day_selected = "";
   }    
   $html.="<option value='$i' $day_selected>$i</option>";
}
$html.="</select> ";

// Year dropdown
$html.="<select name=\"".$name."_year\" style='width: 22%;'>";
$html.="<option value=''>Year</option>";
for($i=$startyear;$i<=$endyear;$i++)
{ 
   if ($i==$break_date['year']) 
   { 
     $year_selected = "selected";
    } else {
     $year_selected = "";
   }         
  $html.="<option value='$i' $year_selected>$i</option>";
}
$html.="</select> ";

return $html;
}

0 个答案:

没有答案