php - 日历表 PHP
问题描述
对于一个小项目,我想创建一个日历表。我想循环几个月和几天。
使用我在这一边找到的代码,它可以循环。
$timestamp = strtotime('next Sunday');
$weekDays = array();
for ($i = 0; $i < NUMBER_OF_COLUMNS; $i++) {
$weekDays[] = strftime('%a', $timestamp);
$timestamp = strtotime('+1 day', $timestamp);
}
$blank = date('w', strtotime("{$year}-{$month}-01"));
?>
<table class='table table-bordered' style="table-layout: fixed;">
<tr>
<th colspan="<?php echo NUMBER_OF_COLUMNS?>" class="text-center"> <?php echo $title ?> <?php echo $year ?> </th>
</tr>
<tr>
<?php foreach($weekDays as $key => $weekDay) : ?>
<td class="text-center"><?php echo $weekDay ?></td>
<?php endforeach ?>
</tr>
<tr>
<?php for($i = 0; $i < $blank; $i++): ?>
<td></td>
<?php endfor; ?>
<?php for($i = 1; $i <= $daysInMonth; $i++): ?>
<?php if($day == $i): ?>
<td><strong><?php echo $i ?></strong></td>
<?php else: ?>
<td><?php echo $i ?></td>
<?php endif; ?>
<?php if(($i + $blank) % NUMBER_OF_COLUMNS == 0): ?>
</tr><tr>
<?php endif; ?>
<?php endfor; ?>
<?php for($i = 0; ($i + $blank + $daysInMonth) % NUMBER_OF_COLUMNS != 0; $i++): ?>
<td></td>
<?php endfor; ?>
</tr>
</table>
<?php
}
// ===========================
/* Set the default timezone */
date_default_timezone_set("Asia/Hong_Kong");
for ($iterateYear=2016; $iterateYear<2018; $iterateYear++) {
for ($iterateMonth=1; $iterateMonth<=12; $iterateMonth++) {
/* Set the date */
$date = strtotime(sprintf('%s-%s-01', $iterateYear, $iterateMonth));
renderCalenderMonth($date);
}
}
但我想以这种格式创建一个表(使用大型(非高效)html代码)。
我喜欢看它:
解决方案
推荐阅读
- amazon-cloudformation - 如何在不更新 ECS 服务任务定义的情况下更新 CloudFormation 堆栈
- c# - C# Windows 窗体 - 循环启动进程
- javascript - 在切换按钮上反应原生播放声音
- python - 如何仅提取第一列中的值以进行张量流
- ios - 我们如何注册一个多平台应用程序以在 iOS 14 中接收通知?
- c++ - Opencv 恢复到比我设置的分辨率更高的分辨率
- php - 哎呀 PHP登录检查散列密码
- python - 我正在尝试通过根据 2 列对其进行排序来组织我的 csv 数据
- c++ - 如何使用 CImg 打开图像?
- php - 带有两个下拉菜单的 PHP 表单未发送