PHP - Simple Easter Date Getter

In this tutorial we will create a Simple Easter Date Getter using PHP. PHP is a server-side scripting language designed primarily for web development. Using PHP, you can let your user directly interact with the script and easily to learned its syntax. It is mostly used by a newly coders for its user friendly environment. So Let's do the coding...

Getting started:

First you have to download & install XAMPP or any local server that run PHP scripts. Here's the link for XAMPP server https://www.apachefriends.org/index.html. Lastly, this is the link for the bootstrap that i used for the layout design https://getbootstrap.com/.

Creating The Interface

This is where we will create a simple form for our application. To create the forms simply copy and write it into you text editor, then save it as index.php.
  1. <!DOCTYPE html>
  2. <?php
  3.         date_default_timezone_set("Etc/GMT+8");
  4. ?>
  5. <html lang="en">
  6.         <head>
  7.                 <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/>
  8.                 <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
  9.         </head>
  10. <body>
  11.         <nav class="navbar navbar-default">
  12.                 <div class="container-fluid">
  13.                         <a class="navbar-brand" href="https://sourcecodester.com">Sourcecodester</a>
  14.                 </div>
  15.         </nav>
  16.         <div class="col-md-3"></div>
  17.         <div class="col-md-6 well">
  18.                 <h3 class="text-primary">PHP - Simple Easter Date Getter</h3>
  19.                 <hr style="border-top:1px dotted #ccc;"/>
  20.                 <div class="col-md-3"></div>
  21.                 <div class="col-md-6">
  22.                         <form method="POST">
  23.                                 <div class="form-group">
  24.                                         <select name="year" class="form-control" required="required">
  25.                                                 <option value="">Select an option</option>
  26.                                                 <?php
  27.                                                         $y = date("Y");
  28.                                                         for($i = $y; $i >= 1965; $i--){
  29.                                                                 echo "<option value='".$i."'>".$i."</option>";
  30.                                                         }
  31.                                                 ?>
  32.                                         </select>
  33.                                 </div>
  34.                                 <?php include 'get_easter.php'?>
  35.                                 <center><button class="btn btn-primary" name="get">Get Easter Date</button></center>
  36.                         </form>
  37.                 </div>
  38.                
  39.         </div>
  40. </body>
  41. </html>

Creating the Main Function

This code contains the main function of the application. This code will calculate the actual date of the easter day. To do this just copy and write the code inside the text editor, then save it as get_easter.php.
  1. <?php
  2.         if(ISSET($_POST['get'])){
  3.                 $year = $_POST['year'];
  4.                 $date = date("F d, Y", easter_date($year));
  5.                 echo "<center><h3 class='text-primary'>".$date."</h3></center>";
  6.         }
  7. ?>
There you have it we successfully created Simple Easter Date Getter using PHP. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!

Add new comment