<form action="" method="get">
年<input type="text" name="y" value="2014" />月<input type="text" name="m" value="<?php echo $_GET['m']; ?>" />日<input type="text" name="d" value="<?php echo $_GET['d'];?>" />
<br />
周期<input type="text" name="i" value="<?php echo $_GET['i']; ?>" />
<br />
<input type="submit" value="提交">
</form>
<?php
$date=$_GET['y'].'-'.$_GET['m'].'-'.$_GET['d'];
$return=$date;
$i=$_GET['i'];
$arr=array(29,30);
$Y=date('y',strtotime($date));
$m=date('m',strtotime($date));
$d=date('d',strtotime($date));
for($i;$i>0;$i--)
{
if($d==31){
echo date('Y-m-t',strtotime("+$i months",strtotime("$Y-$m-5")));
echo '<br>';
continue;
}
if(in_array($d,$arr)&&($i+$m)%12==2){
$y=date('Y',strtotime($return));
echo '<br >';
echo date('Y-m-t',strtotime("$y-2"));
echo '<br />';
continue;
}
$return=date("Y-m-d", strtotime("+$i months", strtotime($date)));
//$return=2月的最后一天
echo $return;
echo '<br />';
}