Display entire file including spaces
I have several files on my vps and would like to display them on the internet. Without moving these files, I would just like to make a php page that gets the files and displays them.
The file in question looks like this (including spacing):
Player: Alive: Score: Ping: Member of Team:
test No 1 41 test
player_1开发者_运维问答 No 1 33 player_1
bug* Yes 1 37 bug*
player 4 No 0 37 player 4
I've tried echo readfile('/path/to/file.txt');
and with file_get_contents
, however, none of the newlines or spacing are preserved.
Here is output with readfile():
Player: Alive: Score: Ping: Member of Team: test No 1 41 test player_1 No 1 33 player_1 bug* Yes 1 37 bug* player 4 No 0 37 player 4 265
Any hints on how to get this to show both spacing/tabs and newlines?
<pre><?=htmlspecialchars(file_get_contents($file))?></pre>
Should be enough for you I believe. htmlspecialchars()
is important to prevent any HTML-like content from being interpreted as HTML.
Use <pre></pre>
. This way the original formatting will be preserved in html.
In an HTML document, newlines and multiple spaces are by default shown as a single space.
Wrap the output in <pre>player: ...</pre>
or any other element with the CSS property white-space: pre;
. For more information, refer to the CSS standard/.
精彩评论