Monday, May 11, 2026
HomeLanguagesHow to use PHP in HTML ?

How to use PHP in HTML ?

In this article, we will use PHP in HTML. There are various methods to integrate PHP and HTML, some of them are discussed below.

You can add PHP tags to your HTML Page. You simply need to enclose the PHP code with the PHP starts tag <?php and the PHP end tag ?>. The code wrapped between these two tags is considered to be PHP code, and it will be executed on the server-side before the requested file is sent to the client browser.

Note: To use PHP in HTML, you have to use the .php extension because In PHP the code is interpreted and run on the server-side.

Syntax:

<html>
  <?php echo "welcome to neveropen" ?>
</html>

 

Example 1:

PHP




<!DOCTYPE html>
<html>
  
<head>
    <style>
        h1 {
            color: green;
        }
    </style>
</head>
  
<body>
    <center>
        <h1>Welcome To GFG</h1>
  
        <h2>
            <?php 
            echo "This is PHP code inside html"
            ?>
        </h2>
    </center>
</body>
  
</html>


Output:

php code inside html

Example 2: 

PHP




<!DOCTYPE html>
<html>
  
<head>
    <style>
        h1 {
            color: green;
        }
    </style>
</head>
  
<body>
    <center>
        <h1>Welcome To GFG</h1>
  
        <p>
<?php 
echo "Complete <strong>Portal</strong> for Geeks."
?>
        <br><br>
        <?php
        echo 'Explore, learn and grow.'
        ?>
        </p>
    </center>
</body>
  
</html>


Output:

php inside html

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32514 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6892 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12107 POSTS0 COMMENTS
Shaida Kate Naidoo
7016 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6975 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS