Jump to content

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


Shantar

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.