APD1993 Posted March 1, 2012 Share Posted March 1, 2012 I am creating a series of PHP scripts that allow for someone to append extra information to an Accident Claim Report. One of these scripts lists the files in a directory called the RCM directory. For the purpose of this, there is only one file in the list named "denman2.txt" and a hyperlink is attached to it so that the updated Accident Claim Report can be displayed. However, I would like it so that a style sheet could be applied to the "denman2.txt" text file, and I was wondering how it would be possible for the "denman2.txt" file to be opened in a format such as an HTML format so that a style sheet can be applied to it. Here is my Append Code: <html> <head><title>Amend File</title></head> <?php if($_POST['append'] !=null) { $filename="C:/xampp/htdocs/rcm/denman2.txt"; $file=fopen($filename, "a"); $msg="Updated Information: " .$_POST['append']. "<br>"; fputs ($file, $msg); fclose($file); } ?> <body> <h1>Do you want to append to a document?</h1> Enter Updated Information: <form action="amendfile2.php" method="post"> <input type="text" size="40" name="append"><br><br> <input type="submit" value="Add updated information to report"> </form> <form action="viewfile3.php" method="post"> <input type="submit" value="View Web Blog"> </form> </body></html> My View File Code: <html><head> <title>RCM File List</title></head> <body> <h1>Files in RCM Directory</h1> <?php $dir="C:/xampp/htdocs/rcm/*txt"; foreach(glob($dir) as $file) { $list = "<li><a href='readfile2.php'>Filename: $file</a></li>"; } ?> <ul> <?php echo $list; ?> </ul> </body> </html> And my Read File Code: <html><head><title>Reading Accident Reports</title></head> <body> <?php function myErrorHandler($errno, $errstr) { echo "<b>Error: </b> [$errno] $errstr"; echo "<br>"; echo "End scripting"; die(); } set_error_handler("myErrorHandler"); $filename="C:/xampp/htdocs/rcm/denman2.txt"; $file = fopen($filename, "r"); while (!feof($file)) { $line=fgets($file,1024); echo "$line<br>"; } fclose($file); ?> </body> </html> Any help is appreciated Quote Link to comment https://forums.phpfreaks.com/topic/258060-how-can-i-read-a-txt-file-in-an-html-format-using-php/ Share on other sites More sharing options...
litebearer Posted March 1, 2012 Share Posted March 1, 2012 Does the txt file already contain any markup? Do you have an example of a typical txt file? Who is creating the txt file. How are they creating the txt file? Quote Link to comment https://forums.phpfreaks.com/topic/258060-how-can-i-read-a-txt-file-in-an-html-format-using-php/#findComment-1322835 Share on other sites More sharing options...
APD1993 Posted March 1, 2012 Author Share Posted March 1, 2012 Does the txt file already contain any markup? Do you have an example of a typical txt file? Who is creating the txt file. How are they creating the txt file? The basic text file is hard typed by me and it consists of : First Name: First Name goes here Last Name: Last Name goes here Age: 18 Complete Weeks Since Accident: 2<br> Can I use <h1> and <p> tags in the text file for a similar effect to HTML (i.e. the <h1> tag will make a level 1 heading in a text file?)? Quote Link to comment https://forums.phpfreaks.com/topic/258060-how-can-i-read-a-txt-file-in-an-html-format-using-php/#findComment-1322838 Share on other sites More sharing options...
litebearer Posted March 1, 2012 Share Posted March 1, 2012 You can fully format it if you want. Quote Link to comment https://forums.phpfreaks.com/topic/258060-how-can-i-read-a-txt-file-in-an-html-format-using-php/#findComment-1322844 Share on other sites More sharing options...
APD1993 Posted March 1, 2012 Author Share Posted March 1, 2012 You can fully format it if you want. Bit of a side question, but what exactly separates a .txt file from a .html file if they can both be formatted? Quote Link to comment https://forums.phpfreaks.com/topic/258060-how-can-i-read-a-txt-file-in-an-html-format-using-php/#findComment-1322847 Share on other sites More sharing options...
litebearer Posted March 1, 2012 Share Posted March 1, 2012 in layman's terms (that me!) primarily how the server and browser decide how to handle it based upon its extension. example: if you name a file index.html, a second file named index.php and a third file named index.txt (all containing the exact same content). the server gets the html file. if you delete the html file, then the server gets the php file. finally, if you delete the php file, the server will NOT get the txt file Clear as mud? Quote Link to comment https://forums.phpfreaks.com/topic/258060-how-can-i-read-a-txt-file-in-an-html-format-using-php/#findComment-1322855 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.