正如其他人已经回答的那样,$nbsp;将输出不间断空格字符。这里是w3 文档 和其他人。
然而,还有其他方法可以做到这一点,现在我更喜欢使用CSS 样式表。也有适合初学者的 w3c 教程。
使用 CSS,您可以这样做:
<html>
<head>
<title>CSS test</title>
<style type="text/css">
p { word-spacing: 40px; }
</style>
</head>
<body>
<p>Hello World! Enough space between words, what do you think about it?</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
“pre”标签定义了预先格式化的文本。它保留了空格和换行符。
<!DOCTYPE html>
<html>
<body>
<pre>This paragraph will be pre-formatted.
I hope this helps!
All spaces will be shown as it is in the original file.
</pre>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)