how to embed html files in php code?

后端 未结 4 1060
野性不改
野性不改 2020-12-03 14:46

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

相关标签:
4条回答
  • 2020-12-03 15:00

    Use the include PHP function for each html file.

    example:

    <?php
    // do php stuff
    
    include('fileOne.html');
    include('fileTwo.html');
    
    ?>
    
    0 讨论(0)
  • 2020-12-03 15:09

    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');
    
    ?>
    
    0 讨论(0)
  • 2020-12-03 15:20

    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>';
        }
    ?>
    
    0 讨论(0)
  • 2020-12-03 15:25

    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

    0 讨论(0)
提交回复
热议问题