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.
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.
- Create Animated Skill Bar Using jQuery, HTML And CSS
- Simple And Best Responsive Web Design Using CSS Part 2
- Show Button On Hover Using HTML And CSS
- Material Design Login Form Using jQuery And CSS
- Animated Progress Bar Using jQuery And CSS
- Dynamic Drop Down Menu Using jQuery, Ajax, PHP And MySQL
- Get Website Statistics Using PHP, jQuery And MySQL
- HTML5 Login And Signup Form With Animation Using jQuery
- Facebook Style Homepage Design Using HTML And CSS
- View Webpage In Fullscreen Using jQuery