Home > Backend Development > PHP Tutorial > php当中换行有关问题

php当中换行有关问题

WBOY
Release: 2016-06-13 13:25:58
Original
899 people have browsed it

php当中换行问题
小议PHP中换行的问题

1.echo  "\n";只是进行了转义,相当于空格,却没有换行,但在源文件中换行了。(网友的解释:\n是ASCII码,浏览器解析的是HTML码,不是ASCII码)

2.echo  "\r\n";经过调试跟1结果一样。

3 .echo   nl2br("\n");  能实现换行, nl2br() 函数在字符串中的每个新行 (\n) 之前插入 HTML 换行符 (
)。

代码:echo     

输出:line1.

line2

htnl代码:line1


line2

4.echo ("$str");echo ("$str
");echo "";echo "
"四种写法都能实现换行。

5.
$str="line1\nline2";

$str1='line1\nlin2';

$str3='lins1\r\nlin2';

echo $str;

echo $str1;

echo $str2;

echo $str3;

?>

输出:line1  line2

line1\nlin2

line1\r\nlin2

line1  line2

html代码:

line1

line2

line1\nlin2

line1\r\nlin2

line1

line2

(待续)

错误在所难免,望各位大神多多提点!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template