How to embed html files in php code?

I have many html files and now I want each of them to call each of the files using some php code. but whenever I try to run php code to call these html files from a folder, this does not work.

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

So, 1,2 and 3 are html files, and now, by clicking the browse button, the user should be directed to the link. How can I solve the problem for including html files in php so that the files will be displayed to the user one by one with the viewing option. And whenever the user clicks the browse button, the user will get a html page being viewed.

Note: I am using xampp server in windows7

Any suggestions would be appreciated ...

+7
source share
4 answers

Use include PHP function for each html file.

Example:

 <?php // do php stuff include('fileOne.html'); include('fileTwo.html'); ?> 
+25
source

A slight improvement in the accepted answer: you prefer readfile() via include() or require() for files other than PHP. This is because include() and require() will be processed as PHP code, so if they contain something similar to PHP (for example, <? ), They can generate errors. Or, worse, a security vulnerability. (There is still a potential security vulnerability if you also display user-provided HTML code, but at least they won’t be able to run the code on your server.)

If the .html files really contain PHP code, you should name them accordingly.

 <?php // do php stuff readfile('fileOne.html'); readfile('fileTwo.html'); ?> 
+2
source

Using opendir and cite files.

Example:

 <?php $dir = "/tmp"; $dh = opendir($dir); while(false !== ($filename = readdir($dh))) { echo $filename . ' <a href="' . $dir . '/' . $filename . '">view</a>'; } ?> 
+1
source

see here loop code for each file in the directory

to know how to encode files in a folder and then just respond tag A with link

0
source

All Articles