HTML inside PHP

2014 年 3 月 16 日4270

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:

 <html> 



<title>HTML with PHP</title>



<body>



<h1>My Example</h1>







<?php



//your php code here



?>







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







<?php



//more php code



?>











</body>



</html>



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:

 <?php 



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.

0 0