Membuat Kalender dengan PHP


12/10/2016 12:04:06 593

Lagi iseng, pengen buat kalender di PHP berikut code-nya. Penjelasannya menyusul :D

<?php
echo date("d M Y");

$jumlah_hari = date("t");
$hari_dalam_minggu_first = date("w", strtotime(date("Y-m") . "-1"));
// $hari_dalam_minggu_last = date("w", strtotime(date("Y-m") . "-".$jumlah_hari));

$d = date("d");
$n = date('t') + $hari_dalam_minggu_first + 0;

$l = (7 - ($n % 7));

$n = $n + $l;

echo "<table border='1'>";
for($i = 0; $i < $n; $i++) {
    if($i % 7 == 0) echo "<tr>"; 
    $t = $i-6+1;
    $t = $t < 1 || $t > $jumlah_hari ? "" : $t; 
    $toDay = $i == $d ? "blue" : "white";
    echo "<td style='background:$toDay'>$t</td>";
    if(($i+1) % 7 == 0) echo "</tr>"; 
}
echo '</table>';
?>