Append to next line in text file using php [duplic

2019-03-02 08:23发布

问题:

This question already has an answer here:

  • Writing a new line to file in PHP 4 answers

I have a php script which passes a value to a .txt file, there is no problem and it works, the only thing is I would like to append the value to the next line instead of just append the value right after another value so instead of "valuevalue" I would like:

value

value

My script:

$filename4 = "EmailsFromSignUp.txt";
$content = file_get_contents($filename4);
$content .= $emailFPay;
file_put_contents($filename4, $content);

回答1:

Try

$content .= PHP_EOL . $emailFPay;


回答2:

$f = fopen("EmailsFromSignUp.txt", "a+");
fputs($f, "\n" . $emailFPay);
fclose($f);


回答3:

$filename4 = "EmailsFromSignUp.txt";
$content = file_get_contents($filename4);
$content .= "\r\n" . $emailFPay;
file_put_contents($filename4, $content);