PHP中换行符\ n的目的是什么? [英] What is the purpose of a newline \n in PHP?

查看:107
本文介绍了PHP中换行符\ n的目的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这用作评论或其他什么,或者它是否在字符之间创建了一个空格,我注意到它的作用。我知道这不会造成换行,所以为什么



那么关于这个的信息很少?实际上有很多关于如何而不是这意味着什么的信息。例如



INPUT



Is this used as a comment or something or does it create a space between characters which I notice that's what it does. I know it dose not create a line break so why is

there so little info about this? There is so much info on how rather than what this means \n actually. For example

INPUT

<?php
echo "a\nbc";
echo "abc";
?>





OUTPUT

a bcabc



我唯一注意到的是它给了我一个空间,我注意到的是它有什么用处?我不能只用空格键添加空格并做同样的事情为什么



这有用吗?请不要引用行话术语。用你自己的话说出最简单的方法可以做到这一点以及为什么任何人都会使用它,因为它没有做任何神奇的输出谢谢你。



我尝试了什么:



很难在Google上找到有关此内容的信息。每个人都对谷歌更感兴趣如何使用它,而不是这样做。



OUTPUT
a bcabc

The only thing I notice is it gives me a space that's all I notice is that what it is good for? Couldn't I just add a space with the space bar and do the same thing why is

this helpful? Please don't just quote from jargon terms. Explain in your own words the most easiest way possible what this does and why would any one use this since it doesn't do any thing magical in output thank you.

What I have tried:

Having a hard time to find info about this on google. Every one is more interested on google on how to use this rather then what this does.

推荐答案

新行确实取决于您运行样本的环境。在Windows中,如果需要新行,则应指定回车符和换行符\r \ n,而Unix则使用\ n。你的问题让我觉得你在Windows上运行你的样本。
A new line really depends on the environment you are running your sample on. In Windows, if you want a new line, you would specify a carriage return and line feed \r\n whereas Unix uses \n. Your question makes me think you ran your sample on Windows.


从这个角度看这没有多大意义。

但是你可以在PRE标签中显示换行符。此外,如果您正在构建基于控制台的应用程序,则此值将反映出来。
from this point of view this does not make much sense.
But you can show line break in PRE tag. Also, if you are building console based application this values will reflect.


检查出来:用PHP实践 - 输出 - Peter Leow的代码博客 [ ^ ]


这篇关于PHP中换行符\ n的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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