如何保留使用PHP / HTML的空白格式? [英] How do I keep whitespace formatting using PHP/HTML?
问题描述
我正在解析文件中的文本并将其存储在一个字符串中。问题是原始文件中的一些文本包含 ASCII art
以及我不想保留的内容。当我在 HTML页面
上打印出字符串时,即使它具有相同的格式和所有内容,因为它位于 HTML
,间距和换行符不会保留。在 HTML
中打印文本的最佳方式与原始文本文件完全相同?
我想举一个例子,但不幸的是,我无法使它在这个Markdown编辑器中正确显示:P
基本上,我想提出如何在HTML中显示 ASCII艺术的建议
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
.
推荐答案
使用< pre>标签(预先格式化),将使用一个单一的间距字体(为您的艺术),并保留所有的空白空间
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>
这篇关于如何保留使用PHP / HTML的空白格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!