Shantar Posted August 28, 2009 Share Posted August 28, 2009 Hi! I'm new in the forum and also relatively new in php. I want to print everything there is in a file for the user to read but both fread and a loop of fgetss only print the words separated by a space. I want to keep all the empty lines in the text as well, just as they are in the file. How do I do that? I'm guessing I'm just trying the wrong functions, surely there must be one that keeps the empty lines? I know I could include the file as it is but it would be convenient to be able to modify the text before printing it. Like converting special characters and so on. I'd like to get the file's text into a variable or at least get each line go through one before printing it. Quote Link to comment https://forums.phpfreaks.com/topic/172222-how-to-print-a-files-content-so-it-wont-erase-empty-lines/ Share on other sites More sharing options...
DavidAM Posted August 28, 2009 Share Posted August 28, 2009 How are you showing the file to the user? If you are retrieving a text file and displaying it in a web page, HTML is going to discard all "extra" whitespace (spaces, carriage-returns, new-lines, tabs, etc) and replace them with a single space. If this is the way you are presenting it, put it inside of <PRE> tags (that tells HTML that the text is "pre-formatted" and it should not be modified). echo "<PRE>" . $output . "</PRE>"; Quote Link to comment https://forums.phpfreaks.com/topic/172222-how-to-print-a-files-content-so-it-wont-erase-empty-lines/#findComment-908057 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.