如果我这样做,我会在我的 index.php 文件中注意到:
<a href=""></a>
<a href=""></a>
相对
<a href=""></a><a href=""></a>
当我使用换行符时,两者之间有更多的空间。我在哪里可以阅读更多关于此的内容?
在 HTML 规范中,任何数量的空白在显示时都会变成一个空白。
正在做:
<a href=""></a> <a href=""></a>
等同于
<a href=""></a>
<a href=""></a>
或者任意数量的回车或中间的空格。
如果你没有空白,那么两者就会相互碰撞。这允许在单词中间加粗等内容。
编辑
感谢 insertusernamehere,HTML 4.01 规范中的确切位置位于:
http://www.w3.org/TR/html401/struct/text.html#h-9.1
特别是,说:
请注意,源文档中单词之间的一系列空格可能会导致呈现完全不同的单词间距(PRE 元素的情况除外)。特别是,用户代理在产生输出字间距时应该折叠输入的空白序列。
This doesn't technically have anything to do with HTML, which itself is just a way of marking up the page. It's actually the CSS styling that collapses white-space via the white-space
property. That property gives you the following options:
normal - This value directs user agents to collapse sequences of white space, and break lines as necessary to fill line boxes.
pre - This value prevents user agents from collapsing sequences of white space. Lines are only broken at preserved newline characters.
nowrap - This value collapses white space as for 'normal', but suppresses line breaks within text.
pre-wrap - This value prevents user agents from collapsing sequences of white space. Lines are broken at preserved newline characters, and as necessary to fill line boxes.
pre-line - This value directs user agents to collapse sequences of white space. Lines are broken at preserved newline characters, and as necessary to fill line boxes.
By default, it is set to normal. This will cause a browser to collapse any sequence of white-space into a single visible space when rendering the HTML structure. Since line breaks are a form of white-space, they also get collapsed.
在 PHP 中,就像 HTML 一样,换行符/回车符通常只是用来使您的文本更清晰。这样可以使将来的代码编辑变得简单易行。
不确定这是否完全相关,但我发现了另一篇与 PHP 格式相关的帖子:PHP 编码风格 - 最佳实践