Saturday, March 6, 2021

Triangle Image Generator in PHP

 A simple program that I wrote that will ask the user to give a number and then the program will generate an inverted triangle using the symbol of asterisk in php programming language.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me at the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.

My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.





Program Listing


index.php


<?php
    $res = "";
    if (isset($_POST["txtNum"])) {
        $num = $_POST["txtNum"];

        while ($num >= 0) {
            $num--;
            for ($i = 0; $i<=$num; $i++) {
                $res .= '*';
            }
            $res .= "<br>";
        }

        $res = "<p>".$res."</p>";
    }
?>

<!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>The Asterisk Problem</title>
    <style>
        form {
            width250px;
            margin200px auto 0;
        }
        fieldset {
            padding20px 25px 20px 20px;
        }
        input {
            width100%;
        }
    </style>
</head>
<body>
    <form action="" method="post">
        <fieldset>
            <legend>The Asterisk Problem</legend>
            <label for="fname">Enter a number:</label>
            <input type="number" id="txtNum" name="txtNum"><br><br>
            <button type="submit">Submit</button>
        </fieldset>
        <?php echo $res; ?>
    </form>
</body>
</html>

No comments:

Post a Comment