All TalkersCode Topics

Follow TalkersCode On Social Media

devloprr.com - A Social Media Network for developers Join Now ➔

How To Write HTML Code In PHP

Last Updated : Mar 11, 2024

How To Write HTML Code In PHP

In this tutorial we will show you the solution of how to write HTML code in PHP, all of us know that php is a server-side scripting language whereas html is client side.

And for this article you have to save your file with .php extension not with .html. Now, let us understand how we are able to write codes.

Step By Step Guide On How To Write HTML Code In PHP :-

Here are two ways with the help of which you are able to write html code in php.

In first you have to open and close php tags again and again whereas in another case you just use your html tags in echo of php. Let us understand both of them one by one.

1. With HTML in PHP

<!DOCTYPE html>
      <html>
        <head>
          <title> Title of the document<title>
        </head>
<body>
 <h1>
  Here, you have to open and close php tags again and again
 </h1>
<?php
 //you have to write php code here
?>
<b>
 We write some html code here
</b>
<?php
 //here we again open and close php tag to write php
?>
</body>
      </html>

2. With the help of echo in PHP

<?php
 echo"<b>you have to write text as it is</b>”;
 echo”<h1> this is another example with help of heading tag.</h1>”;
?>
  1. First, we write <! DOCTYPE html> which we used as an instruction to the web browser about what version of HTML file is written in.
  2. Secondly, the <html> tag is used to indicate the beginning of an HTML document.
  3. As above now <head> tag is used to contain information about web page.
  4. In this tag a <title> tag is used which helps us to specify a webpage title. Both <head> and <title> tags are Paired tags.
  5. So, both have </head> and </title> ending tags respectively.
  6. Thirdly, <body> tag is used to define the webpage body. All the contents to show on website are written here.
  7. Here, we create a heading tag and then bold tag. and after both tags we use php.
  8. For this we open and close php tags i.e. <?php ?>. All the php content must be written inside this tag.
  9. At last, the <body> and <html> tags are closed with </body> and </html> respectively.
  10. Whereas in second example, we directly create php and all the content written inside this tag. For using html here.
  11. In echo tag of php we use html tags. You can see the example of this paragraph in above code.

Conclusion :-

At last here in conclusion, we can say that with the help of this article we are able to write html code in php in two different ways. I hope this tutorial on how to write HTML code in PHP helps you.