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.
Onepage is a must-have single page WordPress theme. Featuring a creative Drag and Drop homepage layout and unique blog layouts, OnePage has a responsive design with clean, handcrafted code that loads fast and is optimized for SEO. Fully customizable, it includes powerful theme options and features to help your site.. 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
Video is a WordPress theme that is built for blogs that have media such as videos. With a like/dislike feature, watch later feature, playlist, low bounce rate, integration with YouTube for view counts, and all the features you expect from MyThemeShop such as search engine optimization, you need Video for your site.. Click Here For More Details
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.