php \r 和 \n 一样吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2018668/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 04:42:07  来源:igfitidea点击:

php \r and \n same thing?

php

提问by Sosa

Why have 2 functions that does the same thing? They both add a linebreak.

为什么有两个功能可以做同样的事情?他们都添加了换行符。

Any diffrence between them?

他们之间有什么区别吗?

回答by Pascal MARTIN

This has nothing to do with PHP, and is a consequence of history :

这与 PHP 无关,是历史的结果:

  • UNIX / Linux use \nfor linebreaks
  • Mac (before OSX)used \r
  • And windows uses a combinaison of both
  • UNIX / Linux 用于\n换行
  • MAC (OSX)之前使用\r
  • Windows 使用了两者的组合

PHP has just kept that behavior -- so it can work with those different OSes and their files.

PHP 保持了这种行为——因此它可以与那些不同的操作系统及其文件一起使用。


Also, note :


另外,请注意:

  • Those are not functions : they are (special) characters
  • They are not exactly the same thing :
  • and, btw, those are another consequence of history : look at their names, and think about typewriters;-)
  • 这些不是函数:它们是(特殊)字符
  • 它们并不完全相同:
  • 顺便说一句,这是历史的另一个后果:看看他们的名字,想想打字机;-)