PHP scripts and programs for Beginner to Master

php programs, php ready to use scripts & functions, css tutorials, html, javascripts, ajax examples for Beginner to Master

Sometimes it is required to show the contents of some text file to the web page. So we can change those contents easily without any problem.

First we will create a simple text file, with some contents.
name it as "test.txt"


These contents are saved in test.txt file.
I am showing you the contents of some text file.

Its very useful to show the contents of the text file in a browser.


Now we will create our php file which will show the contents of the test.txt file to the webpage.


$file1="test.txt";
if (file_exists($file1))
{
$file = fopen("test.txt", "r");
while (!feof($file))
{
$display = fgets($file, filesize("test.txt"));
echo $display . "
";
}
fclose($file);
}
else
{
echo "Error occured ! ! ! Try again or report it to us";
}
?>
?>


Now when we execute this script, it will show the contents of the test.txt to our page.
In this script we are checking whether file exists or not, it it doesnt exists then we will show the error message.

I'm reading: Display text file contents on webpage in phpTweet this!

2 comments:

Works Perfectly many thanks for the code

Regards
James

Dude that works excellent , by any chance you will know how to display the lines sequentially , when I run the script everything in the file is on the same line

Post a Comment