Php 文件内容不为';t从文件\u获取\u内容中计算换行符

Php 文件内容不为';t从文件\u获取\u内容中计算换行符,php,file,fwrite,Php,File,Fwrite,我有两个名为index.php和detail.php的php文件 我的问题是,我甚至认为这个脚本可以正确地写入文本文件,但当它写入detail.php的内容时,它会写入\n而不是换行符 预期产出: A B C D 我得到: A B C\nD 以下是文件的代码: index.php <?php $filename= 'logs/'.$d.'a.txt'; $extra=file_get_contents("detail.php"); $somecontent = "A\nB\n".$e

我有两个名为
index.php
detail.php
的php文件

我的问题是,我甚至认为这个脚本可以正确地写入文本文件,但当它写入
detail.php
的内容时,它会写入
\n
而不是换行符

预期产出:

A
B
C
D
我得到:

A
B
C\nD
以下是文件的代码:
index.php

<?php

$filename= 'logs/'.$d.'a.txt';
$extra=file_get_contents("detail.php");
$somecontent = "A\nB\n".$extra;

$handle = fopen($filename, 'a');
fwrite($handle, $somecontent);
fclose($handle);

?>
<?php

echo 'C\nD';

?>
file\u get\u contents
的结果直接写入,就像复制粘贴一样,
\n
字符不被视为换行符

我所尝试的:

detail.php

<?php

$filename= 'logs/'.$d.'a.txt';
$extra=file_get_contents("detail.php");
$somecontent = "A\nB\n".$extra;

$handle = fopen($filename, 'a');
fwrite($handle, $somecontent);
fclose($handle);

?>
<?php

echo 'C\nD';

?>
=>
echo'C\r\nD'

=>
echo'C\\nD'

=>
echo'C\\r\\nD'


=>
echo'C'.PHP_EOL'D'

要在字符串中使用\n\r\n etc,必须将它们放在双引号中,而不是单引号中,例如回显“C\r\nD”

删除单引号,并使用双引号<代码>'
->

你在运行什么操作系统?。因为每个人都说使用单引号,但没有人告诉你为什么要特别使用单引号。嗨,试试这个代码