php创建文本文件.换行是错误的

Til*_*eck 2 php text file download line-breaks

我使用php创建一个文件,可以在按下链接时下载.

已经尝试了许多代码变体.没理由这个不应该工作:

$output = 'test    spaces, test 
enter, test n, \ntest nr, \n\rtest nt, \n\ttest html-br, <br /><br>end of line';
$output .= '\r\n';
$output .= 'blahblah';
header('Content-type: text/plain');
header('Content-Disposition: attachment;filename="'.$filename.'.txt"');
print $output;
exit;
Run Code Online (Sandbox Code Playgroud)

但是返回的文件以两个我没有插入的空格开始.\ r \n上没有换行符.

如果我在记事本++中打开文件,我会在'enter'上获得一个换行符在普通的记事本中,即使在那里也没有.下载的文本文件中的输出在引号之间是这样的:

  In notepad++
  "  test    spaces, test 
  enter, test n, \ntest nr, \n\rtest nt, \n\ttest html-br, <br /><br>end of line\r\nblahblah"
Run Code Online (Sandbox Code Playgroud)

所以.我究竟做错了什么?在标题之前输出一些东西,所以标题不起作用?

更新:感谢您的帮助.两个正确答案在同一时间.订购"最早的第一个"时的第一个答案被标记为正确答案.使用单引号解决了这个问题.

输出开头的两个空格的问题与给定示例中的代码/ php无关.它是使用的框架中的工件.

gnu*_*nur 8

换行符(使用\n&\r)仅在双引号中识别,而不是在单引号中识别.