I want to get a GET value from the url and store it in a file. I just can't get it in the format which I want it.
Code:
<?php
$emailaccount = $_GET['email'];
$emailaccount .= '\n';
file_put_contents($file, $emailaccount, FILE_APPEND | LOCK_EX);
echo 'done' . PHP_EOL;
?>
URL looks like:
www.website.com/index.php?email=account@gmail.com
My *.txt file should look like:
1account@gmail.com
2account@gmail.com
3account@gmail.com
But my file doesn't look like this, every value is on the same line, why?
Changing $emailaccount .= '\n';
to $emailaccount .= "\r\n";
should do it.
EDIT
Here is why: \r\n is used for system compatibility and double quotes are needed in order for PHP to parse it as newline characters instead of a literal string.