我正在尝试在日期 1 到 9 的前面添加 0,因为日期列在下拉菜单中。这是我的代码,我认为使用 d 会添加前导零,但似乎不起作用。我没有太多的 php 经验,所以这是一个远景......提前谢谢你!
<?PHP
FUNCTION DateSelector($inName, $useDate=0)
{
/* create array so we can name months */
$monthName = ARRAY(1=> "January", "February", "March",
"April", "May", "June", "July", "August",
"September", "October", "November", "December");
/* if date invalid or not supplied, use current time */
IF($useDate == 0)
{
$useDate = TIME();
}
/* make month selector */
ECHO "<SELECT NAME=" . $inName . "month>\n";
FOR($currentMonth = 1; $currentMonth <= 12; $currentMonth++)
{
ECHO "<OPTION VALUE=\"";
ECHO INTVAL($currentMonth);
ECHO "\"";
IF(INTVAL(DATE( "m", $useDate))==$currentMonth)
{
ECHO " SELECTED";
}
ECHO ">" . $monthName[$currentMonth] . "\n";
}
ECHO "</SELECT>";
/* make day selector */
ECHO "<SELECT NAME=" . $inName . "day>\n";
FOR($currentDay=1; $currentDay <= 31; $currentDay++)
{
ECHO "<OPTION VALUE=\"$currentDay\"";
IF(INTVAL(DATE( "d", $useDate))==$currentDay)
{
ECHO " SELECTED";
}
ECHO ">$currentDay\n";
}
ECHO "</SELECT>";
/* make year selector */
ECHO "<SELECT NAME=" . $inName . "year>\n";
$startYear = DATE( "Y", $useDate);
FOR($currentYear = $startYear - 0; $currentYear <= $startYear+2;$currentYear++)
{
ECHO "<OPTION VALUE=\"$currentYear\"";
IF(DATE( "Y", $useDate)==$currentYear)
{
ECHO " SELECTED";
}
ECHO ">$currentYear\n";
}
ECHO "</SELECT>";
}
?>