<p>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 <code>ASCII art</code> and whatnot that I would like to preserve.  When I print out the string on the <code>HTML page</code>, even if it does have the same formatting and everything since it is in <code>HTML</code>, the spacing and line breaks are not preserved.  What is the best way to print out the text in <code>HTML</code> exactly as it was in the original text file?<br>
I would like to give an example, but unfortunately, I was not able to get it to display correctly in this markdown editor :P<br>
Basically, I would like suggestions on how to display <code>ASCII art in HTML</code>.</p>

[{'answer_id': 36657, 'author': 'UnkwnTech', 'author_id': 115, 'author_profile': 'https://Stackoverflow.com/users/115', 'pm_score': 3, 'selected': False, 'text': '<p>When you print the data use <a href="http://www.php.net/manual/en/function.nl2br.php" rel="noreferrer"><code>nl2br()</code></a> to convert <code>\\n</code> and <code>\\r\\n</code> into <code>&lt;br&gt;</code></p>\n'}, {'answer_id': 36658, 'author': 'Grant', 'author_id': 30, 'author_profile': 'https://Stackoverflow.com/users/30', 'pm_score': 7, 'selected': True, 'text': "<p>use the &lt;pre&gt; tag (pre formatted), that will use a mono spaced font (for your art) and keep all the white space</p>\n\n<pre><code>&lt;pre&gt;\ntext goes here and here \n             and here and here            Some out here\n     ▄             ▄█▄ █▄       ▄\n ▄█▀█▓ ▄▓▀▀█▀ ▀▀▀█▓▀▀ ▀▀    ▄█▀█▓▀▀▀▀▀▓▄▀██▀▀\n██  ██ ▀██▄▄ ▄█  ▀ ░▒ ░▒   ██  ██ ▄█▄ █▀ ██\n█▓▄▀██  ▄ ▀█▌▓█    ▒▓ ▒▓   █▓▄▀██ ▓█ ▀▄  █▓\n█▒  █▓ ██▄▓▀ ▀█▄▄█▄▓█ ▓█   █▒  █▓ ▒█  ▓█▄ ▒\n    ▀▒           ▀  ▀ █▀       ▀▒  ▀  █▀  ░\n\n&lt;/pre&gt;  \n</code></pre>\n\n<p>You might have to convert any &lt;'s to &amp;lt; 's</p>\n"}, {'answer_id': 14956689, 'author': 'Igor L.', 'author_id': 1315125, 'author_profile': 'https://Stackoverflow.com/users/1315125', 'pm_score': 4, 'selected': False, 'text': '<p>the <code>&lt;pre&gt;</code> and <code>&lt;/pre&gt;</code> might not be ideal in textarea etc..</p>\n\n<p>When wanting to preserve new line - <code>\\n</code> and <code>\\n\\r</code> use <a href="http://php.net/manual/en/function.nl2br.php">nl2br</a> as mentioned by UnkwnTech and Brad Mace.</p>\n\n<p>When wanting to preserve spaces use <a href="http://www.php.net/str_replace">str_replace</a>:</p>\n\n<p><code>str_replace(\' \', \'&amp;nbsp;\', $stringVariable);</code></p>\n\n<p>When both use this:</p>\n\n<pre><code>$result = str_replace(\' \', \'&amp;nbsp;\', $stringVariable);\n$result = nl2br($result);\n</code></pre>\n'}, {'answer_id': 29119413, 'author': 'Divyanshu Jimmy', 'author_id': 2442565, 'author_profile': 'https://Stackoverflow.com/users/2442565', 'pm_score': 3, 'selected': False, 'text': '<p>For all those searchng for preserving  the text  fetched from database , this worked for me , setting CSS as following  , </p>\n\n<pre><code>pre {\n     white-space: pre-line;\n     text-align : left;\n  }\n</code></pre>\n\n<p>in html : </p>\n\n<pre><code>&lt;pre &gt;\n     &lt;?php echo htmlentities($yourText ) ; ?&gt;\n&lt;/pre&gt;\n</code></pre>\n'}, {'answer_id': 59850570, 'author': 'OsowoIAM', 'author_id': 2335697, 'author_profile': 'https://Stackoverflow.com/users/2335697', 'pm_score': -1, 'selected': False, 'text': '<p>just echo the necessary special characters (\\s, \\n, or \\r ) along with your string in your PHP code.</p>\n\n<pre><code>&lt;?php \n\necho ("hello world \\n")\n\n?&gt;\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/36656', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3831/']