I made a simple calendar in PHP 7.0, could anyone help with simplification? Any advice appreciated. It works, but I totally believe it can be improved. I am a beginner.
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$chosen_year = filter_input(INPUT_GET, 'chosen_year', FILTER_SANITIZE_SPECIAL_CHARS);
$chosen_month = filter_input(INPUT_GET, 'selected_month', FILTER_SANITIZE_SPECIAL_CHARS);
$do_update_button = filter_input(INPUT_GET, 'month_year', FILTER_SANITIZE_SPECIAL_CHARS);
if (isset($do_update_button)) {
$number_of_days = date("t", mktime(0, 0, 0, $chosen_month, 1, $chosen_year));
$english_order = date("l", mktime(0, 0, 0, $chosen_month, 1, $chosen_year));
} else {
$number_of_days = date("t", mktime(0, 0, 0, date('n'), 1, date('Y')));
$english_order = date("l", mktime(0, 0, 0, date('n') , 1, date('Y')));
}
$blank_cell = ' ';
$array_of_days = array($blank_cell,"1","2","3","4","5","6","7","8","9","10",
"11","12","13","14","15","16","17","18","19","20",
"21","22","23","24","25","26","27","28","29","30",
"31");
// search for the first day of month
if($english_order == "Monday") {
$a = 1;
}
else if($english_order == "Tuesday") {
array_unshift ($array_of_days, $blank_cell);
$a = 2;
}
else if($english_order == "Wednesday") {
array_unshift ($array_of_days, $blank_cell, $blank_cell);
$a = 3;
}
else if($english_order == "Thursday") {
array_unshift ($array_of_days, $blank_cell, $blank_cell, $blank_cell);
$a = 4;
}
else if($english_order == "Friday") {
array_unshift ($array_of_days, $blank_cell, $blank_cell, $blank_cell, $blank_cell);
$a = 5;
}
else if($english_order == "Saturday") {
array_unshift ($array_of_days, $blank_cell, $blank_cell, $blank_cell, $blank_cell, $blank_cell);
$a = 6;
}
else if($english_order == "Sunday") {
array_unshift ($array_of_days, $blank_cell, $blank_cell, $blank_cell, $blank_cell, $blank_cell, $blank_cell);
$a = 7;
}
$lastDay = count($array_of_days);
?>
<form action = "callender.php" method = "GET">
<table border = "1">
<!-- choose year -->
<th colspan = "2">
<select name = "chosen_year">
<option value = "<?php echo date('Y'); ?>" selected = "selected"><?php echo date('Y') ?> </option>
<?php
$chosen_year = filter_input(INPUT_GET, 'chosen_year', FILTER_SANITIZE_SPECIAL_CHARS);
function getYear() {
$years = "";
for ($year = 2030; $year >= 2000; $year--) {
$years .= $year . " ";
}
return $years;
}
$years = explode (" ", getYear());
foreach ($years as $number => $chose_year) {
?>
<option value="<?php echo $chose_year; ?>"<?php if(isset($chosen_year) and ($chosen_year) == $chose_year) { ?> selected = "selected"<?php } else if(date('Y') == $number) { ?> selected ='selected'<?php } ?>> <?php echo $chose_year; ?></option>
<?php
}
?>
</select>
</th>
<!-- select month -->
<th colspan = "3">
<select name = "selected_month">
<?php
$chosen_month = filter_input(INPUT_GET, 'selected_month', FILTER_SANITIZE_SPECIAL_CHARS);
$months = array(1 => "January", "February", "March", "April", "May",
"June", "July", "August", "September", "October", "November",
"December");
foreach($months as $number2 => $chose_month) {
?>
<option value="<?php echo $number2;?>"<?php if(isset($chosen_month) and ($chosen_month)== $number2) { ?> selected = "selected"<?php } ?>>
<?php echo $chose_month; ?></option>
<?php } ?>
</select>
</th>
<th colspan = "2">
<input type = "submit" value = "update" name="month_year" />
</th>
<tr><td>Mon</td> <td>Tue</td><td>Wed</td><td>Thu</td><td>Fri</td><td>Sat</td><td>Sun</td></tr>
<?php
$i = 1;
while ($i < $number_of_days + $a) {
if ((($i - 1 ) % 7 == 0)) {
$DayToBrake = $i;
echo "\n<tr>";
}
else if ($i != 1) echo "</td>\n";
echo "<td>";
if (($chosen_year == date('Y')) and ($chosen_month == date('n')) and date('j') == $array_of_days[$i]) {
echo '<strong style="color:red">' .$array_of_days[$i]. '</strong>';
} else {
echo $array_of_days[$i];
}
if (($i % 7 == 0) || ($i == $lastDay)) {
$DayToBrake = $i;
echo "</td></tr>";
}
$i++;
}
echo "</td></tr>\n";
?>
<tr>
<td colspan = "5">
<?php $m = date('n'); {echo '<strong>'." Is"." ".$months[$m]." ". date('Y').'</strong>';} ?>
</td>
<td colspan = "2">
</td>
</tr>
</table>
</form>