Showing posts with label leap year. Show all posts
Showing posts with label leap year. Show all posts

Friday, May 30, 2014

Leaper Year Checker in PHP


In learning computer programming one of the most common programming problem that is being presented by teachers in their students is how to determine whether the given year is a leap year or not. A leap year according is a year that has additional day most of the time it will fall on the month of February commonly the month of February has only 28 days but in leap year with will fall until 29 days. Leap year occurs every fours years their are some sports events that is being held every four years just like the Olympic games and FIBA basketball tournaments. 

Let us start discussing how the program works in our leap year check first of all we need to create our user interface in our web page we are using HTML and CSS to make our layout more presentable and easy to interact with our user. Our program will ask the user to enter the year in the text field after which it will give the user an option to check if the year is a leap year or not. Their are two command button the first one is the convert and the other one is the clear all. The convert button will check if the year given by the user is a leap year or not a leap year and the clear button will allow the user to clear the text fields in order for the user to enter new year.

Again this code that I wrote to check the given year of the user whether it is a leap year or not is intended for beginners in PHP web programming I hope you will find my work useful in your programming assignments and projects.

Thank you very much until the next article.


Sample Output of Our Program


Program Listing

<?php
/* Leap Year Checker
   May 30, 2014 Friday
   Author : Mr. Jake R. Pomperada, MAED-IT
   Email Address: jakerpomperada@yahoo.com

*/   

// Trapping any possible errors
error_reporting(0);

$value1 = trim($_REQUEST['value1']);


function is_leap_year($year)
{
$ts = strtotime("$year-01-01");
return date('L', $ts);
}


  
 // For submit button process of Computation
   
 if ($_REQUEST['convert'])
    {
if (empty($value1)) {
     $message = "Year Cannot Be Empty.";
$solve="";
}
    elseif (!is_numeric($value1))
{
$message = "Year Value Cannot be a String.";
$solve="";
}
elseif ( !is_leap_year($value1) ) 
{
      $output = "$value1 not a leap year.";
      $solve= $output;
     }
   else {
       $output = "$value1 is a leap year.";
      $solve= $output;
     }
 }

 if ($_REQUEST['clear'])
    {
    $value1="";
    $value2="";
$message="";
   }
   
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Roman Numberal Converter</title>
<style type="text/css">
<!--
body {
background-color: #CCFFFF;
}
.style3 {
font-size: 18px;
color: #80FF00;
}
.style5 {
font-family: Arial, Helvetica, sans-serif;
font-size: 16px;
color: #0000CC;
font-weight: bold;
}
.style10 {
font-size: 16px;
font-weight: bold;
}
.style11 {
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
color: #0000CC;
}
-->
</style></head>

<body>
<div align="center">
  <p><img src="title.jpg" width="511" height="93" /></p>
  <p class="style5 style10">Created By</p>
  <p class="style5">Mr. Jake R. Pomperada, MAED-IT</p>
  <p class="style5">Email Address: jakerpomperada@yahoo.com</p>
  <form id="form1" name="form1" method="post" action="">
  <table width="450" border="0">
    <tr>
     
 <td width="235"><div align="left"><span class="style5">Please enter a year </span></div></td>
      <td width="205"><label>
        <input type="text" name="value1" maxlength=5
value="<?php echo trim($value1); ?>" />
      </label></td>
 <?php
     echo "<font color=#0000CC><b><h4>".$message."</b></h4></font>";
?>
    </tr>
    <tr>
      <td><div align="left"></div></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
     
 <td><div align="left" class="style11">The Result is </div></td>
      <td><input type="text" name="value2" maxlength=5 
 value="<?php echo trim($solve); ?>" readonly />
 </td>
    </tr>
    <tr> </tr>
  <td height="26"><p align="justify">
    <input type="submit" name="convert" value="Convert" />
    <input type="submit" name="clear" value="Clear All" />
  </p></td>
  </table>
  </form>
  <p class="style3">&nbsp;</p>
</div>
<p>&nbsp;</p>
</body>
</html>