<html>
<head>
	<meta charset="UTF-8">
	<title>Kalendarz</title>
	<style>.inactive{color:#999;}</style>
</head>
<body>
<?php
function cal_monday($year, $month) {
	if(date('w', $tmp = strtotime($year.'-'.$month.'-01')) == 1) {
		return date('Y-m-d', $tmp);
	} else {
		return date('Y-m-d', strtotime('last monday', $tmp));
	}
}

function cal_sunday($year, $month) {
  $d = date('t',strtotime($year.'-'.$month.'-01'));
  if(date('w', $tmp = strtotime($year.'-'.$month.'-'.$d)) == 0) {
	return date('Y-m-d', $tmp);
  } else {
	return date('Y-m-d', strtotime('next sunday', $tmp));
  }
}

$y = 2018;
$m = 12;

$start = cal_monday($y,$m);
$stop  = cal_sunday($y,$m);
$day   = $start;

echo '<table><tr>';

for($i = 0; $day < $stop; $i++) {
	$day = date('Y-m-d', strtotime('+' . $i . ' DAY ' . $start));
	if(!($i%7) && $i) echo '</tr><tr>';
	printf('<td%s>%d</td>', 
		date('n', strtotime($day)) != $m ? ' class="inactive"' : '',
		explode('-',$day)[2]);
}

echo '</tr></table>';

?>
</body>
</html>