PHP: trying to create a new line with “\n”

2019-01-11 06:27发布

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

标签: php newline
15条回答
聊天终结者
2楼-- · 2019-01-11 07:09

It will be written on a new line if you examine the source code of the page. If you want it to appear on a new line when it is rendered in the browser, you'll have use a <br /> tag instead.

查看更多
Ridiculous、
3楼-- · 2019-01-11 07:11
echo "foo<br />bar";
查看更多
Rolldiameter
4楼-- · 2019-01-11 07:13

the html element break line depend of it's white-space style property. in the most of the elements the default white-space is auto, which mean break line when the text come to the width of the element. if you want the text break by \n you have to give to the parent element the style: white space: pre-line, which will read the \n and break the line, or white-space: pre which will also read \t etc. note: to write \n as break-line and not as a string , you have to use a double quoted string ("\n") if you not wanna use a white space, you always welcome to use the HTML Element for break line, which is <br/>

查看更多
登录 后发表回答