Adding HTML in PHP Script

There are two ways to use HTML on your PHP page. The first way is to put the HTML outside of your PHP tags. You can even put it in the middle if you close and reopen the <?php -and- ?> tags. Here is an example of putting the HTML outside of the tags:

 <title>HTML with PHP</title>
 <h1>My Example</h1>
 //your php code here

 <b>Here is some more HTML</b>

 //more php code


As you can see you can use any HTML you want without doing anything special or extra in your .php file, as long as it is outside of the PHP tags.

The second way to use HTML with PHP is by using PRINT or ECHO. By using this method you can include the HTML inside of the PHP tags. This is a nice quick method if you only have a line or so to do. Here is an example:

 Echo "<html>";
 Echo "<title>HTML with PHP</title>";
 Echo "<b>My Example</b>";

 //your php code here

 Print "<i>Print works too!</i>"; 

Using one or both of these methods you can easily embed HTML code in your PHP pages, to give them a nicer more formatted look, and make them more user friendly.

Tagged with: , , , ,
Posted in PHP

Leave a Reply

Recent Comments