PHP program to check if a given number is ODD or EVEN

Below is the php script to find the given number is odd or even.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ODD or EVEN</title>
</head>
<body>
    <h2>PHP script to find given number is ODD or EVEN </h2>
    <form action="" method="post">
        <input type="text" name="num" />
        <input type="submit" />
    </form>
    <?php
        if ($_POST)
        {
            $num = $_POST['num'];
            if(!is_numeric($num))
            {
                echo "String not allowed.
                Input should number";
                return;
            }
            if($num % 2==0)
            { 
                echo "Number is an even number";
            }
            else
            {
                echo "Number is an odd number ";
            }
        }
    ?>

</body>
</html>


Thank You.

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