How are \ r \ t and \ n different from each other?

In the code below, I do not know how these characters functionally differ from each other: \ r \ t \ n. Does anyone have an explanation or description for them?

Here is a sample code:

<!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> 
+4
source share
2 answers

\n - newline character

\t is a tab character

and \r for 'return'

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

+16
source

The character \n means literally a new line. This will skip to the beginning of the next new line.

The \t character means adding a bookmark (usually 4 spaces, but can be easily 2 or 8 depending on the context).

The \r character is no longer used as often. This means carriage return, which means going to the beginning of the line. It was used along with \n to make sure that even "old" printers reach the beginning of the next line.

+5
source

Source: https://habr.com/ru/post/1469392/


All Articles