gpt4 book ai didi

php - 换行符有什么用?

转载 作者:太空狗 更新时间:2023-10-29 15:20:08 25 4
gpt4 key购买 nike

我不太明白:换行符的目的是什么?

如果我这样做:

<?php
echo "This is a test. \n";
echo "This is another test.";
?>

代码导致两个句子在同一行。为什么\n 不会导致第二句出现在第二行?

句子各占一行,如果我这样做的话:

<?php
echo "This is a test. <br>";
echo "This is another test.";
?>

但我也看到有人这样做:

<?php
echo "This is a test. <br>\n";
echo "This is another test.";
?>

这基本上会产生与第二个代码片段相同的输出。有人愿意解释一下吗?

最佳答案

HTML standard将换行符视为另一个空白字符,这就是为什么 <br>标签存在。但是请注意,换行符将在 <pre> 中起作用标签,或带有 white-space:pre 的元素CSS 样式。

第三个例子只是为了制作“漂亮”的 HTML:它使“查看源代码”和肉眼检查变得更容易。否则,您将得到一大串 HTML。

关于php - 换行符有什么用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/554566/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com