Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to embed html files in php code?

Tags:

html

php

I have many html files and now i want to call each of the files one by one using some php code. but whenever i try to run the php code for calling those html files from the folder, it doesnot work.

    1.html view
    2.html view
    3.html view

So, 1,2 and 3 are the html files and now by clicking view user should be directed to the link. How can i solve the problem for incorporating html files in php, so that the files will be displayed to user one by one with a view option. And whenever user will click view, user will get the html page viewed.

Note: i m using xampp server in windows7

Any suggestions will be appreciated...

like image 909
sp2 Avatar asked Sep 06 '12 06:09

sp2


People also ask

Can you embed HTML in PHP?

Yes, HTML can be embedded inside an 'if' statement with the help of PHP.

How do you embedded PHP in HTML code explain?

Step 1: Firstly, we have to type the Html code in any text editor or open the existing Html file in the text editor in which we want to use the PHP. Step 2: Now, we have to place the cursor in any tag of the <body> tag where we want to add the code of PHP. And, then we have to type the start and end tag of PHP.

Which of the following codes is used to embed PHP code in an HTML page?

The Embed PHP code is the standard one that is a normal html document; we have written the PHP code on the html page. The above code is the basic syntax for embedding the php code in html page with the help of <script> tags; it is also another type of style for portable codes.

How many ways you can embed PHP code in an HTML page?

PHP provides four different ways to do this. As you'll see, the first, and preferred, method looks like XML. The second method looks like SGML. The third method is based on ASP tags.


2 Answers

Use the include PHP function for each html file.

example:

<?php
// do php stuff

include('fileOne.html');
include('fileTwo.html');

?>
like image 69
Bashevis Avatar answered Sep 28 '22 18:09

Bashevis


Small improvement to the accepted answer: you should prefer readfile() over include() or require() for non-PHP files. This is because include() and require() will be processed as PHP code, so if they contain something that looks like PHP (like <?), they may generate errors. Or worse yet, a security vulnerability. (There is still potential security vulnerability if you are displaying user-provided HTML too, of course, but they at least won't be able to run code on your server.)

If the .html files actually contain PHP code, you should name them appropriately.

<?php
// do php stuff

readfile('fileOne.html');
readfile('fileTwo.html');

?>
like image 23
Kip Avatar answered Sep 28 '22 19:09

Kip