作成:2005/10/03
更新:2023/05/12

作る!
 
カウンターでも作る
カレンダーでも作る
認証ページでも作る
 
知る!
 
GOOGLEっぽいクエリー文字
PHPのロゴ表示
URL文字列分割
いろんな情報を取得する
テーブルの色を1つおきに変える
ファイルの更新日を自動出力
ファイルをダウンロードさせる
プルダウン作成2パターン
メニューを作る
数字の表示方法
日付
日本語縦書き表示
長い文章を表示する(ヒアドキュメント)
 
このサイトは以下の環境で
動作しています。
Apache/2.4.52 (Ubuntu)
PHP version 8.1.2-1ubuntu2.15
 

 

TOP -> 作る!

-- カレンダーでも作る! --

<?php
// 現在の年
$year  = date('Y');
// 現在の月
$month = date('m');
// 現在の年・月の1日
$day   = mktime(0, 0, 0, $month, 1, $year);
// その月の最初の曜日
$first = date('w', $day);
// その月の日数
$total = date('t', $day);
// その月の週数
$week  = ceil($total / 7);
if (($total % 7 > 7 - $first) || ($total % 7 == 0 && $first != 0)) {
    $week++;
}
?>
<table border="0" cellpadding="0" cellspacing="0">
 <tr>
  <th><font color="#FF0000">日</fonr></th><th>月</th><th>火</th><th>水</th><th>木</th><th>金</th><th><font
color="#000FFF">土</fonr></th>
 </tr>
 <tr>
<?php
echo $year . "年" . $month . "月";
for ($i=1;$i<=$week*7;$i++) {
    if ($i % 7 == 1) {
        echo "<tr>";
    }
    if (($i -1 < $first) || ($i > $total + $first)) {
        echo "<td align=center><font color=#c0c0c0>・</font></td>";
    } else {
        if ($i % 7 == 1) {
            $col = "#FF0000";
        } elseif ($i % 7 == 0) {
            $col = "#000FFF";
        } else {
            $col = "#000000";
        }
        echo "<td align=center><font color=" . $col . ">" . ($i - $first) . "</font></td>";
    }
    if ($i % 7 == 0) {
        echo "</tr>";
    }
}
?>
 </tr>
</table>
      

表示結果:

2024年04月
123456
78910111213
14151617181920
21222324252627
282930

-- 知ってるといいかも --

 
Copyright © 2024 php.thm.jp All rights reserved.