I have 2 php files named index.php and detail.php.
My porblem is that even thought this script writes to the text file correctly but when it writes content of detail.php it writes \n instead of the newline.
Expected Output:
A
B
C
D
I get:
A
B
C\nD
Here is the code for the files:
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);
?>
detail.php
<?php
echo 'C\nD';
?>
The result of file_get_contents is directly written as if copy-pasted, the \n chracter is not considered as newline.
What i have tried:
detail.php
=>echo 'C\r\nD'
=>echo 'C\\nD';
=>echo 'C\\r\\nD';
=>echo 'C'.PHP_EOL.'D';