使用PHP date()
函数或任何其他下划线函数(如cal_days_in_month
),我如何在特定月份打印每一天?
谢谢你们,谢天谢地!
我想要这样的输出:
(也许用foreach
循环完成?)
...whatever day name starts the month
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Sunday
Monday
Tuesday
...ect
until end of month
答案 0 :(得分:2)
我相信我写的以下功能会做到这一点。
<?php
function calendar ($month, $year)
{
$num = cal_days_in_month(CAL_GREGORIAN, $month, $year);
$today = strtotime(date("Y-m-d"));
for ($i = 0; $i < $num; $i++)
{
$date = strtotime($year . "-" . $month . "-" . ($i + 1));
if ($today === $date)
{
echo ("!!");
}
$day=strftime("%A", $date);
echo (($i + 1) . " " . $day . "<BR>");
}
}
?>
已编辑:现在包含请求。
答案 1 :(得分:1)
这个应该给你编写所需函数的代码。没有底层的PHP函数可以做到这一点。 Grab all Wednesdays in a given month in PHP
另见官方php文档http://www.php.net/manual/en/class.datetime.php
PHP - List all days in a month in a year
你有尝试过的代码吗?
答案 2 :(得分:1)
function printDay($month,$year=FALSE){
if(!$year){
$year=date('Y');
}
$num = cal_days_in_month(CAL_GREGORIAN, $month, $year);
for($day=1;$day<=$num;$day++){
echo date('l', strtotime($year.'-'.$month.'-'.$day));
echo "<br>";
}
}
printDay(8);