Preview:
<?php
$month = date('m');
$year = date('Y');

// Get the first day of the month
$firstDayOfMonth = mktime(0, 0, 0, $month, 1, $year);

// Number of days in the month
$numberDays = date('t', $firstDayOfMonth);

// Get the name of the month
$monthName = date('F', $firstDayOfMonth);

// Get the day of the week for the first day of the month
$dayOfWeek = date('D', $firstDayOfMonth);

// Create a table to organize the calendar
echo "<h1>$monthName $year</h1>";
echo "<table>";
echo "<tr><th>Sun</th><th>Mon</th><th>Tue</th><th>Wed</th><th>Thu</th><th>Fri</th><th>Sat</th></tr><tr>";

// Pad the calendar with empty cells if the month doesn't start on a Sunday
if($dayOfWeek != 'Sun') {
  $blankDaysBefore = date('w', $firstDayOfMonth);
  for($i = 0; $i < $blankDaysBefore; $i++) {
    echo "<td></td>";
  }
}

// Fill in the rest of the calendar with the days of the month
for($dayCounter = 1; $dayCounter <= $numberDays; $dayCounter++) {
  $currentDay = mktime(0, 0, 0, $month, $dayCounter, $year);
  if(date('w', $currentDay) == 0) {
    echo "</tr><tr>";
  }
  echo "<td>$dayCounter</td>";
}

echo "</tr></table>";
?>
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter