\t和\n彼此有什么不同? [英] How are \r \t and \n different from one another?

查看:126
本文介绍了\t和\n彼此有什么不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的代码中,我不知道这些字符在功能上有何不同:: r\t\n。有人对此有解释或说明吗?

In the code below, I don't know how these characters are different functionally from one another: \r \t \n. Does anyone have an explanation or description for these?

以下是一些示例代码:

<!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>


推荐答案

\n 是换行的符号

\t 是制表符的符号

\r 用于返回

您可以在这里找到更多信息: \r和between有什么区别\n?

You can find more information here: What is the difference between \r and \n?

这篇关于\t和\n彼此有什么不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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