PHP中\\\<br/>和PHP_EOL有什么好处? [英] What is the benefit of \n and PHP_EOL in PHP?

查看:111
本文介绍了PHP中\\\<br/>和PHP_EOL有什么好处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在PHP中输出一个换行符,并在浏览器中查看。我只能使用< br /> 标记来管理它。



当我使用 \\\
,什么也没有发生,那么使用 \\\
有什么好处呢?还有什么是 PHP_EOL 的好处?当我将它连接到一个字符串时,只打印一个空格而不是换行符。 解决方案

Web浏览器解释输出PHP程序为HTML,所以 \\\
\r\\\
不会出现任何内容,只是如在HTML文件中插入换行符。另一方面,< br /> 在解释的HTML中创建一个新行(因此行BReak)。因此,< br /> 会换行,而 \r\\\
不会做任何事情。


I'm trying to output a newline character in PHP that gets viewed in a web browser. I can only manage it by using the <br /> tag.

When I use \n, nothing occurs, so what is the benefit of using \n? Also what is the benefit of PHP_EOL? When I concatenate it to a string, just a space is printed not a newline.

解决方案

A web browser interprets the output of a PHP program as HTML, so \n and \r\n will not appear to do anything, just like inserting a newline in an HTML file. On the other hand, <br /> makes a new line in the interpreted HTML (hence "line BReak"). Therefore, <br /> will make new lines, whereas \r\n will not do anything.

这篇关于PHP中\\\<br/>和PHP_EOL有什么好处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆