How to embed PHP code in an HTML page ? Last Updated : 12 Feb, 2022 Comments Improve Suggest changes Like Article Like Report PHP is the abbreviation of Hypertext Preprocessor and earlier it was abbreviated as Personal Home Page. We can use PHP in HTML code by simply adding a PHP tag without doing any extra work. Example 1: First open the file in any editor and then write HTML code according to requirement. If we have to add PHP code then we can add by simply adding <?php ..... ?> tags in between and add your PHP code accordingly. PHP <!DOCTYPE html> <html> <head> <title>PHP</title> </head> <body> <h1> <?php echo "hii GeeksforGeeks " ?> </h1> </body> </html> Output: Example 2: In this, we can use PHP code in different lines so that we can make a webpage according to the need and put code wherever necessary as shown in the below example PHP <html> <body> <h2>Welcome to GeeksforGeeks</h2> <?php echo "Good morning"; ?> <p>Good to see you</p> <?php $str = "This is GeeksforGeeks portal"; echo " $str."; ?> </body> </html> Output: Example 3: In this, we use PHP code in HTML document using the post method where we can pass value in HTML form and receive in the PHP post method. PHP <html> <body> <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> Name: <input type="text" name="fname"> <input type="submit"> </form> <?php if ($_SERVER["REQUEST_METHOD"] == "POST") { $str = $_POST['fname']; if (empty($str)) { echo "String is empty"; } else { ?> <h1> <?php echo $str ?> </h1> <?php } } ?> </body> </html> Output: Comment More infoAdvertise with us Next Article How to embed PHP code in an HTML page ? R rohanmittal1366 Follow Improve Article Tags : HTML HTML-Questions PHP-Questions Similar Reads How to parse HTML file in PHP ? In this article, we will learn to parse HTML in PHP. What is parsing? Generally parsing is converting one data type to another. It means how we can convert various data types to HTML. For example: Converting string to HTML. Why do we need parsing? To add the dynamic data (HTML content) at a certain 2 min read How to Add Map in HTML? When building websites, including a map is often necessary to display important locations, such as office addresses, at the footer or on dedicated pages. Adding a map enhances user experience, making it easier for users to locate your business or other important points of interest.PrerequisitesBasic 3 min read How to Embed Audio and Video in HTML? HTML stands for HyperText Markup Language. It is used to design web pages using a markup language. It is a combination of Hypertext and Markup language. HTML uses predefined tags and elements that tell the browser how to properly display the content on the screen. So, in this article, we will learn 4 min read How to define a piece of computer code in HTML? The <code> element in HTML is used to display computer code, ensuring it is displayed with a fixed-width font for proper alignment and readability. Unlike basic heading tags, the <code> tag maintains the correct formatting of the code, including spaces and line breaks. HTML offers variou 2 min read How to create a New Line in PHP ? When working with text output in PHP, like creating a webpage, sending an email, or saving to a file, it's important to know how to add a new line. Adding a new line helps break up the text, makes it easier to read, and keeps it looking right whether it's shown in a browser, a terminal, or a file.Ho 2 min read Like