<php
$year = trim(strip_tags($_REQUEST['year']));
if(strlen($year) != 4)//判断长度
{
die('请输入正确日期');
}
if(!is_numeric($year))//判断提交的是否是数字
{
die('请输入正确日期');
}
if(substr($year,0,2) != 19 or substr($year,0,1) != 2)
{
die('请输入正确日期');
}
>
当然,最好用JS来做了。PHP是提交后进行判断验证。
¥t = time()+3600*8;&#47;&#47;这里和标准时间相差8小时需要补足¥tget = ¥t-3600*24*5;&#47;&#47;比如5天前的时间echo date(&quot;Y-m-d H:i:s 星期w&quot;,¥tget);&#47;&#47;格式按你需要选取附带:相关时间参数:a - &quot;am&quot; 或是 &quot;pm&quot;A - &quot;AM&quot; 或是 &quot;PM&quot;d - 几日ei二位数字,若不足二位则前面补零; 如: &quot;01&quot; 至 &quot;31&quot;D - 星期几,三个英文字母; 如: &quot;Fri&quot;F - 月份,英文全名; 如: &quot;January&quot;h - 12 小时制的小时; 如: &quot;01&quot; 至 &quot;12&quot;H - 24 小时制的小时; 如: &quot;00&quot; 至 &quot;23&quot;g - 12 小时制的小时,不足二位不补零; 如: &quot;1&quot; 至 12&quot;G - 24 小时制的小时,不足二位不补零; 如: &quot;0&quot; 至 &quot;23&quot;i - 分钟; 如: &quot;00&quot; 至 &quot;59&quot;j - 几日,二位数字,若不足二位不补零; 如: &quot;1&quot; 至 &quot;31&quot;l - 星期几,英文全名; 如: &quot;Friday&quot;m - 月份,二位数字,若不足二位则在前面补零; 如: &quot;01&quot; 至 &quot;12&quot;n - 月份,二位数字,若不足二位则不补零; 如: &quot;1&quot; 至 &quot;12&quot;M - 月份,三个英文字母; 如: &quot;Jan&quot;s - 秒; 如: &quot;00&quot; 至 &quot;59&quot;S - 字尾加英文序数,二个英文字母; 如: &quot;th&quot;,&quot;nd&quot;t - 指定月份的天数; 如: &quot;28&quot; 至 &quot;31&quot;U - 总秒数w - 数字型的星期几,如: &quot;0&quot; (星期日) 至 &quot;6&quot; (星期六)Y - 年,四位数字; 如: &quot;1999&quot;y - 年,二位数字; 如: &quot;99&quot;z - 一年中的第几天; 如: &quot;0&quot; 至 &quot;365&quot;
/
获取指定月份的第一天开始和最后一天结束的时间戳
@param int $y 年份 $m 月份
@return array(本月开始时间,本月结束时间)
/
function mFristAndLast($y="",$m=""){
if($y=="") $y=date("Y");
if($m=="") $m=date("m");
$m=sprintf("%02d",intval($m));
$y=str_pad(intval($y),4,"0",STR_PAD_RIGHT);
$m>12||$m<1$m=1:$m=$m;
$firstday=strtotime($y$m"01000000");
$firstdaystr=date("Y-m-01",$firstday);
$lastday = strtotime(date('Y-m-d 23:59:59', strtotime("$firstdaystr +1 month -1 day")));
return array("firstday"=>$firstday,"lastday"=>$lastday);
}
因为你的格式有误,时间参数不要有逗号,逗号后面无法识别默认取当前年份了。
1echo date('Ymd',strtotime("24 Dec 2014"));
Ymd确实是返回8位年月日,不知道你要什么格式的。
以上就是关于怎样检验输入php表单的年份全部的内容,包括:怎样检验输入php表单的年份、php如何获取最近5年的年份、php获取当年的每个月的第一天和最后一天时间戳的函数等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)