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
Use the include PHP function for each html file.
example:
<?php
// do php stuff
include('fileOne.html');
include('fileTwo.html');
?>
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');
?>
Using opendir and loop throught the files.
Example:
<?php
$dir = "/tmp";
$dh = opendir($dir);
while(false !== ($filename = readdir($dh)))
{
echo $filename . ' <a href="' . $dir . '/' . $filename . '">view</a>';
}
?>
see here Loop code for each file in a directory
to know how to loop the files in the folder, then just echo an A tag with a link