file_put_contents, file_append and line breaks

后端 未结 7 1332
旧时难觅i
旧时难觅i 2020-12-30 19:32

I\'m writing a PHP script that adds numbers into a text file. I want to have one number on every line, like this:

1
5
8
12

If I use f

7条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-30 19:41

    annoyingregistration, what you have there is absolutely fine. PHP_EOL and "\n" are exactly the same.

    The code you provided theres nothing wrong with it so it must be the value of $commentnumber that has a space at the end of it. as stated, run your $commentnumber through the trim() function.

    file_put_contents($filename, trim($commentnumber . "\n"), FILE_APPEND);
    

    Good luck.

提交回复
热议问题