How embed html in php?

Want to add HTML to a PHP file? While HTML and PHP are two separate programming languages, you might want to use both of them on the same page to take advantage of what they both offer.

With one or both of these methods, you can easily embed HTML code in your PHP pages to format them better and make them more user-friendly. The method you choose depends on your specific situation.

HTML in PHP

Your first option is to build the page like a normal HTML web page with HTML tags, but instead of stopping there, use separate PHP tags to wrap up the PHP code. You can even put the PHP code in the middle if you close and reopen the tags.

This method is especially useful if you have a lot of HTML code but want to also include PHP.

Here's an example of putting the HTML outside of the tags [PHP is bold here for emphasis]:

 
HTML with PHP

My Example



Here is some more 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's outside and separate from the PHP tags.

In other words, if you want to insert PHP code into an HTML file, just write the PHP anywhere you want [so long as they're inside the PHP tags]. Open a PHP tag with  like you see above.

Use PRINT or ECHO

This other way is basically the opposite; it's how you'd add HTML to a PHP file with PRINT or ECHO, where either command is used to simply print HTML on the page. With this method, you can include the HTML inside of the PHP tags.

This is a good method to use for adding HTML to PHP if you only have a line or so to do.

In this example, the HTML areas are bold:


Much like the first example, PHP still works here regardless of using PRINT or ECHO to write HTML because the PHP code is still contained inside the proper PHP tags.

I want to create table inside php script .. Is there any way that i could create table inside php script.?


asked Aug 9, 2013 at 4:59

Karan BhatiaKaran Bhatia

7811 gold badge7 silver badges16 bronze badges

2

You can do like

HTML in PHP :


Or You can write like.

PHP in HTML :


     
Name


Means:
You can open a PHP tag with and then write your html code. When needed to add more PHP, just open another PHP tag with

Updated


answered Aug 9, 2013 at 5:00

Rohan KumarRohan Kumar

40k11 gold badges73 silver badges103 bronze badges

2

Can place code anywhere

Chủ Đề