Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: trying to create a new line with "\n"

Tags:

php

newline

i'm writing this:

echo "foo"; echo "\n"; echo "bar"; 

and "bar" is not written in the line below.

What am i doing wrong?

Javi

like image 457
ziiweb Avatar asked Apr 20 '10 11:04

ziiweb


People also ask

Does \n make a new line?

The \n Character The other way to break a line in C++ is to use the newline character — that ' \n ' mentioned earlier. This is line one. This is line two.

What is the \n in PHP?

\n is the newline or linefeed, other side \r is the carriage return. They differ in what uses them. Windows uses \r\n to signify the enter key was pressed, while Linux and Unix use \n to signify that the enter key was pressed.

What is \n line break?

Newline (frequently called line ending, end of line (EOL), next line (NEL) or line break) is a control character or sequence of control characters in a character encoding specification (e.g., ASCII, EBCDIC) that is used to signify the end of a line of text and the start of a new one.

Is BR and \n same?

The <br> or <br /> tag is an HTML element that will display everything after this <br> or <br /> by starting from new line when rendered in browser while the \n is used to jump to next line in the source code or the output prompt in standard output.


1 Answers

Newlines in HTML are expressed through <br>, not through \n.

Using \n in PHP creates a newline in the source code, and HTML source code layout is unconnected to HTML screen layout.

like image 117
Tomalak Avatar answered Oct 03 '22 13:10

Tomalak