PHP program to check if a given year is Leap year or not

PHP program to check if a given year is Leap year or not


In this tutorial, you will be learning how to check if a given year is Leap Year or not in php.

Below is the PHP script to find the given year is leap year or not.

<html>
<head>
    <title>Leap Year</title>
</head>
<body>

    <h2>PHP script to find given year is a leap year or not </h2>

    <form action="" method="POST">
        <input type="number" name="year" />
        <input type="submit" />
    </form>

    <?php
        if($_POST)
        {
            $year $_POST['year'];

            if(!is_numeric($year))
            {
                echo "String not allowed.
                Input should be a number";
                return ;
            }
            if( ($year % 4==0) and ($year % 100!=0) or ($year % 400==0) )
            {
                echo "$year is a leap year";
            }
            else
            {
                echo "$year is not a leap year";
            }
        }
        ?>
</body>
</html>


Thank for reading

© Copyright - 2018 - 2022 | All rights reserved at Funda of Web IT