Basic PHP code | Hypertext Preprocessor Code example - Simple example of basic PHP code

Basic PHP Code:

PHP (Hypertext Preprocessor) is a server-side scripting language widely used for web development. 

Here's a simple example of basic PHP code:

php code
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Basic PHP Example</title>
</head>
<body>

    <h1>My First PHP Page</h1>

    <?php
        // PHP code starts here

        // Displaying a simple message
        echo "<p>Hello, World!</p>";

        // Variables
        $name = "John";
        $age = 25;

        // Displaying variables
        echo "<p>Name: $name</p>";
        echo "<p>Age: $age</p>";

        // Conditional statement
        if ($age >= 18) {
            echo "<p>$name is an adult.</p>";
        } else {
            echo "<p>$name is a minor.</p>";
        }

        // PHP code ends here
    ?>

</body>
</html>

Explanation:

- The PHP code is embedded within `<?php ... ?>` tags.
- `echo` is used to output content to the web page.
- Variables are declared using the `$` symbol.
- A simple conditional statement checks if the age is greater than or equal to 18.
- The PHP code is part of an HTML document, allowing seamless integration of dynamic content.

To run PHP code, you need a server environment with PHP installed. You can use local development tools like XAMPP, WampServer, MAMP, or set up a server environment on a web hosting platform.

Save the above code in a file with a `.php` extension (e.g., `index.php`) and access it through a web browser by navigating to `http://localhost/your-folder/index.php`, where `your-folder` is the directory where your PHP file is located.
ShowHideComments