tags:

views:

1294

answers:

2

I'm parsing text from a file and storing it in a string. The problem is that some of the text in the original files contains ASCII art and whatnot that I would like to preserve. When I print out the string on the HTML page, even if it does have the same formatting and everything, since it is in HTML, the spacing and linebreaks are not preserved. What is the best way to print out the text in HTML exactly as it was in the original text file?
I would like to give an example, but unfortunately, I was not able to get it to display correctly in this markdown editor :P
Basically, I would like suggestions on how to display ASCII art in HTML.

+1  A: 

When you parse the data use nl2br() to convert \n/\r\n into

Unkwntech
+7  A: 

use the <pre> tag (pre formatted), that will use a mono spaced font (for your art) and keep all the white space

<pre>
text goes here and here 
             and here and here            Some out here
     ▄             ▄█▄ █▄       ▄
 ▄█▀█▓ ▄▓▀▀█▀ ▀▀▀█▓▀▀ ▀▀    ▄█▀█▓▀▀▀▀▀▓▄▀██▀▀
██  ██ ▀██▄▄ ▄█  ▀ ░▒ ░▒   ██  ██ ▄█▄ █▀ ██
█▓▄▀██  ▄ ▀█▌▓█    ▒▓ ▒▓   █▓▄▀██ ▓█ ▀▄  █▓
█▒  █▓ ██▄▓▀ ▀█▄▄█▄▓█ ▓█   █▒  █▓ ▒█  ▓█▄ ▒
    ▀▒           ▀  ▀ █▀       ▀▒  ▀  █▀  ░

</pre>

You might have to convert any <'s to &lt; 's

Grant
porneL
+1 for 1337 vintage style
GerManson