Saturday, September 29, 2018

Yearly Calendar in PHP

A very simple program to generate yearly calendar using PHP. I am using WAMP in creating and running this code.

 I am currently accepting programming work, it projects, school 

programming projects, thesis and capstone projects, IT consulting 

work, computer tutorials, and web development work kindly contact me in the following email address for further details.  If you want to advertise in my website kindly contact me also in my email address also. Thank you.
My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.

My personal website is http://www.jakerpomperada.com




Sample Program Output


Program Listing

index.php

<html>
<head>
<title>Yearly Calendar in PHP</title>
<style>
table { margin: 20px; }
caption { text-decoration: underline; }
body { font-family:arial; font-size:12px;color:blue; background-color:yellow; }
h1 {background-color:blue;color:white; text-align:center;}
h2 {background-color:black;color:white; text-align:center;}
</style>
</head>

<body>
<br>
<h1> Yearly Calendar in PHP </h1>
<h2> Created By Mr. Jake R. Pomperada, MAED-IT </h3>
<br>
<?php
function make_calendar($month, $year) {
$first_day = mktime(0, 0, 0, $month, 1, $year);

// date() has lots of possible parameters - here we use them one by one
$days_in_month = date("t", $first_day);
$month = date("m", $first_day);
$month_name = date("F", $first_day);
$year = date("Y", $first_day);
$week_day = date("w", $first_day);

// % means "modulus", which calculates remainders
$week_day = ($week_day + 7) % 7;

$calendar = "<table><caption>$month_name $year</caption><tr>";

// create the table header for the table, showing each day name across the top
$day_names = array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
foreach ($day_names as $d) $calendar .= "<th>$d</th>";
    $calendar .= "</tr><tr>";

// if the first day isn't a Sunday, we need to indent it a little
if ($week_day > 0) $calendar .= "<td colspan=\"$week_day\"> </td>";

// now create the rest of the calendar
for ($day = 1; $day <= $days_in_month; ++$day, ++$week_day) {
if ($week_day == 7) {
$week_day = 0;
$calendar .= "</tr><tr>";
}

$calendar .= "<td>$day</td>";
}

// if the last day isn't a Saturday, we need to create the empty cells at the end
if ($week_day != 7) $calendar .= "<td colspan=\"" . (7 - $week_day) . "\"> </td>";

$calendar .= "</tr></table>";
return $calendar;
}

// create all 12 months of the year
echo "<table><tr>";
for ($i = 1; $i < 13; ++$i) {
echo "<td>" . make_calendar($i, 2018) . "</td>";
// every four months, make a break so we can see them all on the same screen
if ($i % 4 == 0) echo "</tr> <tr>";
}
echo "</tr></table>";
?>

</body>
</html>


No comments:

Post a Comment