新行字符有什么好处? [英] What good is new line character?

查看:110
本文介绍了新行字符有什么好处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我这样做的话:
$ b
我没有真正理解它:一个换行符的目的是什么? $ b

 <?php 
echoThis is a test。\\\
;
回声这是另一项测试。;
?>

两个句子的代码结果都在同一行中。为什么不是\\\
会导致第二句话在第二行?



如果我这样做,每个句子都在自己的行中:

 <?php 
echoThis is a test。< br>;
回声这是另一项测试。;
?>

但我也看到有人这样做:

 <?php 
echoThis is a test。< br> \\\
;
回声这是另一项测试。;
?>

基本上会得到与第二个代码片段相同的输出。有人在乎解释这一点吗?

HTML标准将换行符视为另一个空格字符,这就是为什么< br> 标签存在。但是请注意,换行符可以在< pre> 标签中使用,也可以在 white-space:pre CSS style。

第三个例子就是让漂亮 HTML:它使得查看源代码更容易,并且可以通过眼睛来检查它。否则,你会有很长的一串HTML。


I don't really get it: what's the purpose of a new line character?

If I do this:

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

Code results in both sentences being in the same line. Why doesn't the \n causes the second sentence being in second line?

The sentences are each in it's own line, if I do:

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

But I have also seen people do this:

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

Which essentially results in the same output as the second code snippet. Someone care to explain this?

解决方案

The HTML standard treats a line break as just another white space character, which is why the <br> tag exists. Note however a line break will work within a <pre> tag, or an element with the white-space:pre CSS style.

The third example is just to make "pretty" HTML: it makes it easier to "view source" and check it by eye. Otherwise, you have a big long string of HTML.

这篇关于新行字符有什么好处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆