How To Get Leap Years From Specified Range Of Years In PHP

admin_img Posted By Bajarangi soft , Posted On 27-11-2020

A leap year have 366 days in a year. A leap year comes after every four years. Hence a leap year is always a multiple of four.For example 2012, 2016, 2020, 2024, etc are leap years.So today to we make list of leap years it we use php script

How To Get Leap Years From Specified Range Of Years In PHP

Complete Code For Getting Leap Years From Specified Range Of Years In PHP.

<!DOCTYPE html>
<html>
<head>
    <title>How To Get Leap Years From Specified Range Of Years In PHP</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet">
</head>
<style>
    body {
        background: black;
    }
</style>
<body>
<body>
<div class="container">
    <br/><br/>
    <div class="text-center">
        <h1 id="color" style="color: white;">How To Get Leap Years From Specified Range Of Years In PHP</h1>
    </div>

    <div class="well">
        <form action="" method="post" >
            <label>Enter From year</label><br>
            <input type="number" name="from_year"  value=""><br><br>
            <label>Enter To year</label><br>
            <input type="number" name="to_year"  value=""><br><br>
            <input type="submit" value="submit" class="btn btn-success" name="submit">
        </form>

        <?php
        if(isset($_POST['submit'])) {
            //get the year
            $from_year = $_POST['from_year'];
            $to_year = $_POST['to_year'];


            function isLeap($year)
            {
                return (date('L', mktime(0, 0, 0, 1, 1, $year)) == 1);
            }

            //For testing
            for ($year = $from_year ; $year < $to_year; $year++) {
                if (isLeap($year)) {
                    echo "$year : LEAP YEAR<br />\n";
                } else {
                    echo "$year : Not leap year<br />\n";
                }
            }
        }
        ?>
    </div>
</div>
</body>
</html>

Related Post