Read HTML From Text File Using PHP
Tuesday, Jan 24, 2017
In this tutorial we will show you how to read HTML content from a text file using PHP.In this we read a text file which is present in our folder and have HTML contents by using this method it will also display inline styling.You may also like read xml file using PHP.
Nexus is a versatile magazine theme packed full of custom widgets and content modules that give you control over your page. The challenge of any magazine theme is to take massive amounts of content and present it to the reader in a clear and structured manner. Nexus achieves this through a strict grid, typographical hierarchy and a clean layout that gives each element just enough room to breath.. Click Here For More Details
To Read HTML From Text File It Takes Only Two Steps:-
- Make a Text file and add some HTML code for reading
- Make a PHP file to read HTML content from a text file
Step 1.Make a Text file and add some HTML code for reading
We make a Text file and save it with a name content.text
<h1>Sample Text File</h1> <p>This is used by our PHP file to read HTML content</p> <br> <table align=center> <tr> <td>Suresh</td><td>PHP Developer</td> </tr> <tr> <td>Pooja</td><td>Web Designer</td> </tr> <tr> <td>Amit</td><td>HTML Developer</td> </tr> <tr> <td>Ram</td><td>Data Analyst</td> </tr> </table>
In this step we create a text file and write some HTML content for reading.You can also add inline styling to your HTML code to display content in style.You may also like read and write csv file using PHP.
Step 2.Make a PHP file to read HTML content from a text file
We make a PHP file and save it with a name read_html.php
<html> <body> <div id="wrapper"> <?php $myfile = fopen("content.txt", "r") or die("Unable to open file!"); echo fread($myfile,filesize("content.txt")); fclose($myfile); ?> </div> </body> </html>
In this step we use PHP fopen function to open our 'content.txt' file in read mode and then use fread() function to display file content.You may also like read and delete file from folder using PHP.
That's all, this is how to read HTML content from text file using PHP .You can customize this code further as per your requirement. And please feel free to give comments on this tutorial.