HTML 和 PHP 中的 'Line feeds' 到底是什么意思?如何在 HTML 和 PHP 代码中添加它们?

What does exactly mean by 'Line feeds' in HTML and PHP? How do they are added in HTML and PHP code?

我正在阅读 PHP 手册,我遇到了以下文本段落:

Line feeds have little meaning in HTML, however it is still a good idea to make your HTML look nice and clean by putting line feeds in. A linefeed that follows immediately after a closing ?> will be removed by PHP. This can be extremely useful when you are putting in many blocks of PHP or include files containing PHP that aren't supposed to output anything. At the same time it can be a bit confusing. You can put a space after the closing ?> to force a space and a line feed to be output, or you can put an explicit line feed in the last echo/print from within your PHP block.

我有以下与上段文字相关的问题:

  1. HTML 中的 'Line feeds' 到底是什么意思?
  2. 如何将它们添加到 HTML 代码以及 PHP 代码中并使其在网络浏览器中可见? HTMLentities/tags/characters是用什么实现的?
  3. 在HTML和PHP的情况下,'Line feed'的含义相同吗?如果不是,两种上下文的含义有何不同?
  4. 为什么 PHP 手册在段落的第一行本身是这样说的? PHP 手册下面这句话想表达什么?

"Line feeds have little meaning in HTML"

  1. 当有人放入许多 PHP 块或包含不应该包含 PHP 的文件时,删除紧跟在结束标记之后的换行符有什么用?>输出什么?

请有人用简单明了、通俗易懂的语言来解答我上面提到的疑惑。如果有人可以通过合适的工作代码示例来回答答案,那将对我更清楚地理解这个概念有很大帮助。

谢谢。

What does exactly mean by 'Line feeds' in HTML?

这是一个通用的计算术语。

The character (0x0a in ASCII) which advances the paper by one line in a teletype or printer, or moves the cursor to the next line on a display.

source: Wiktionary

How to add them to the HTML code

按键盘上的回车键。请注意(除了 <pre> 等几个例外)所有白色 space 字符在 HTML 中都可以互换。新行将被视为 space.

as well as PHP code

同上……或者您可以在字符串文字中使用转义序列 \n

and make visible in a web browser?

您引用的 material 是在谈论使源代码看起来更漂亮。您通常不希望换行符在浏览器中可见。

您可以改用 <pre> 元素。

<pre> 元素之外(以及它们默认的 CSS 设置),您可以使用 space 而不是换行,以获得与 [=41= 相同的效果].

What HTML entities/tags/characters are used to achieve this?

&#10;

...但是您引用的 material 最后一句话中给出的建议可能是更好的方法。

'Lines feed'在Html和Php中都是'New line',只是语法不同而已。

  1. 如果是 Html 标签,您可以使用 <br><br/> 标签作为 Lines 提要。基本上,此标记在 Html 属性块的输出中显示一个新行,而 运行 通过浏览器。

  2. 对于<br>标签可以拿下面的例子:

<html> <body>

<p> To break lines<br>in a text,<br/>use the br element. </p>

</body> </html>

输出:
要在文本中换行

使用 br 元素。

  1. 在 Php 的情况下,您可以使用 '\n' 换行。

  2. 如果你使用的是Php中的字符串,那么不用写,

回显"New \nLine";

您可以使用 nl2br() 函数来获取换行符,例如:

echo nl2br("New \nLine");

输出: