Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!--Write a PHP script AwesomeCalendar.php which creates a calendar in HTML for a given year.
- Styling the calendar is optional. Semantic HTML is required. Hint: Embed HTML in your PHP code.
- Use tables or divs for structuring the calendar. Look for a way to find the day of the week.-->
- <!DOCTYPE html>
- <html>
- <head lang="en">
- <meta content="text/html" charset="UTF-8">
- <title>Awesome Calendar</title>
- <style type="text/css">
- #wrapper {
- margin: auto;
- width: 750px;
- display: block;
- }
- header {
- text-align: center;
- border-bottom: 1px solid #000;
- }
- h1 {
- font-family: Geneva, sans-serif;
- font-size: 40px;
- margin: 5px;
- }
- section {
- padding-top: 15px;
- }
- .monthTable {
- display: inline-table;
- margin-right: 20px;
- }
- .monthTable:last-child {
- margin-right: 0;
- }
- tr th {
- border-bottom: 1px solid #000;
- }
- tr:last-child > th:last-child {
- color: #F00;
- }
- td {
- font-weight: 600;
- }
- </style>
- </head>
- <body>
- <div id=wrapper>
- <?php
- function buildAwesomeCalendar($givenYear) {
- echo "<header><h1>$givenYear</h1></header><section><table id='outerTable'><tbody><tr><td>";
- $months = array('Януари', 'Февруари', 'Март', 'Април', 'Май', 'Юни', 'Юли', 'Август', 'Септември',
- 'Октомври', 'Ноември', 'Декември');
- foreach ($months as $key => $month) {
- echo "<table class='monthTable'><thead><tr><th colspan=\"7\">$months[$key]</th></tr><tr><th>По</th>" .
- '<th>Вт</th><th>Ср</th><th>Чт</th><th>Пе</th><th>Сб</th><th>Не</th></tr></thead><tbody>';
- $currentDay = mktime(0, 0, 0, ((int)$key + 1), 1, $givenYear);
- $daysInMonth = date('t', $currentDay);
- $weekCounter = 0;
- $printedDays = 0;
- do {
- $tableRow = '<tr>';
- for ($i = 1; $i < 8; $i++) {
- $dayOfWeek = date('N', $currentDay);
- if ($i < $dayOfWeek || $i > $dayOfWeek || ($printedDays >= $daysInMonth)) {
- $tableRow .= "<td> </td>";
- continue;
- }
- $dayOfMonth = date('j', $currentDay);
- $tableRow .= "<td>$dayOfMonth</td>";
- $printedDays++;
- $currentDay = strtotime('+1 day', $currentDay);
- }
- echo $tableRow . '</tr>';
- $weekCounter++;
- } while ($weekCounter <= 5);
- echo '</tbody></table>';
- if (((int)$key % 4) == 3) {
- if ($key < 11) {
- echo '</td></tr><tr><td>';
- } else {
- echo '</td></tr>';
- }
- }
- }
- echo '</tbody></table></section>';
- }
- buildAwesomeCalendar(2014);
- ?>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement