How to Read HTML From Text File Using PHP

In this tutorial we will show you how to read HTML content from a text file using PHP. The fopen() function opens a file or URL and The fread() reads from an open file. You may also like How to Send HTML Form array in Codeigniter using Ajax and How to Read XML file Using PHP.

Text File

<h1>Sample Text File</h1>

PHP and HTML Code

<html>
    <body>
    <?php
        $myfile = fopen("text.txt", "r") or die("Unable to open file!");
        echo fread($myfile,filesize("text.txt"));
        fclose($myfile);
    ?>
    </body>
</html>

Leave a Reply

Your email address will not be published. Required fields are marked *