I have a password protected text file and to make it password protected, i used a password protector script (which works great) but it required me to rename the text file to .php on my server. This went fine, however, when I open this text file in any browser on windows, i do not seeing any new lines (I used to see them)
I tried writing -" ", "", " ". I think it has to do with the browser thinking its a .php file i guess.
Browsers uses HTML to format text (contained in html of course)
use <br>
or <p>
Also considering your file is a .php
it's a normal behaviour that your webserver will send it as text/html
By default the output of PHP scripts are rendered as HTML, which means that whitespace is folded. If you want to change this back to text then you need to set the Content-Type
header to "text/plain", either in the web server or via the header()
function.
You need to use <br>
, as html is being rendered in the browser.
This is because the server is sending a different MIME type. It is now sending text/html
(the default type returned by PHP) rather than text/plain
.
Your browser is then expecting HTML. Line breaks are just like any other white space in HTML, so they are essentially meaningless for what you are trying to do.
You can use this to fix it:
header('Content-Type: text/plain');
Be sure to put that at the top of your code, or at least before you output anything.
This causes the server to send the MIME type you are expecting.
That's because the browser would see the content as html and in html a newline is just a whitespace
I am not sure if I understood your question properly, but in two cases there is a solution:
-You output the text: In this case, you have to use
<br>
-You want to write it with new lines in the file: Use the PHP-Constant
PHP_EOL
which means End-of-Line. This inserts always a correct break.