php -\r\t 和\n 彼此有何不同?

标签 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>

最佳答案

\n 是换行符

\t 是制表符

\r 用于“返回”

您可以在此处找到更多信息:What is the difference between \r and \n?

关于php -\r\t 和\n 彼此有何不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15423001/

相关文章:

php - GROUP BY 到数组

regex - 使用 Perl 的正则表达式查找项目

c++ - 根据 C/C++ 标准, "'“与 "\' 相同”吗?

php - 如何显示子类别的面包屑

php - 如何使用 youtube api v3 获取 youtube 视频的完整描述

python - 如何有选择地转义 Python 字符串中的百分比 (%)?

java - Java中如何获取控制字符的字节数

C - if 条件中的指针

python - 如何在python中找到字符串向量之间的所有组合

php - 如何在从 PHP 从数据库中检索数据时将 2 个单元格加入表中?