\ r\t和\n是如何彼此不同的?

Pre*_*lah 6 php escaping character

在下面的代码中,我不知道这些字符在功能上是如何彼此不同的:\ r\t \n.有没有人对这些有解释或描述?

以下是一些示例代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <title>Sorting words in a block of text by length</title>
        <link rel="stylesheet" type="text/css" href="common.css" />
    </head>
    <body>
        <h1>Sorting words in a block of text by length</h1>

<?php

$myText = <<<END_TEXT
But think not that this famous town has 
only harpooneers, cannibals, and 
bumpkins to show her visitors. Not at 
all. Still New Bedford is a queer place. 
Had it not been for us whalemen, that 
tract of land would this day perhaps 
have been in as howling condition as the 
coast of Labrador.
END_TEXT;

echo "<h2>The text:</h2>";
echo "<div style=\"width: 30em;\">$myText</div>";

$myText = preg_replace( "/[\,\.]/", "", $myText );
$words = array_unique( preg_split( "/[ \n\r\t]+/", $myText ) );
usort( $words, create_function( '$a, $b', 'return strlen($a) - strlen($b);
' ) );

echo "<h2>The sorted words:</h2>";
echo "<div style=\"width: 30em;\">";

foreach ( $words as $word ) {
    echo "$word ";
}
echo "</div>";

?>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

Lem*_*urr 22

\n 是新线的象征

\t 是标签的符号

并且\r是'回归'

您可以在此处找到更多信息:\ r和\n之间有什么区别?


Sho*_*hoe 10

\n符号字面意思是新的生产线.这将进入下一个新行的开始.

\t符号是指添加选项卡(通常是4个空格但可以很容易地根据上下文2或8).

\r经常不再使用该符号.这意味着回车意味着转到线的起点.它与一起使用\n以确保即使是"旧"打印机也会到达下一行的开头.