Jump to content

How to print a file's content so it won't erase empty lines


Recommended Posts

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.

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>";

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.