Php calendar tutorial

In this tutorial I show you how to create a simple calendar for a project without needing the library as a fullcalendar. We must paste it in the index.php view class

<?php
      include ('calendar.php');
      // Prevent not null month
      if ($_GET['month']) {
        $month = $_GET['month'];
      }
      else {
        $month = date("Y-m");
      }
      //Get an array from Calendar 
      $data = Calendar::calendar_month($month);

      $mes = $data['month'];
      // Get the month in Spanish
      $mespanish = Calendar::spanish_month($mes);

?>

To download it calendar.php and import it click link below

https://github.com/artyom-developer/calendar-php/blob/master/calendar.php

An array for example: Month May 2019


Json result from Calendar.php


An array $ data [‘calendar’] has 5 or 4 weeks depending on the month and the item of $ data [‘calendar’] has a variable called «data» -> $ dayweek [‘data’] represents days of the week (from Monday to Sunday) as well as the previous image that shows us how it is.

<!-- start of the week -->
      <?php foreach ($data['calendar'] as $weekdata) { ?>
        <div class="row">
          <!-- Day cycle from days per week-->
          <?php foreach ($weekdata['datos'] as $dayweek) { ?>

          <?php if ($dayweek['mes']==$mes) { ?>
            <div class="col box-day">
              <?= $dayweek['dia']; ?>
            </div>
          <?php }else{ ?>
          <div class="col box-dayoff">
          </div>
          <?php } ?>


          <?php } ?>
        </div>
      <?php } ?>

So the result is:

Complete code view index.php


https://github.com/artyom-developer/calendar-php


Un comentario sobre “Php calendar tutorial”

  1. Thanks for the tutorial and the ones you publish, do you think there is the possibility of teaching us how to make a calendar as a timeline?

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *