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
pauls answer has the correct approach but he has a mistake. what you need ist the following:
file_put_contents($filename, trim($commentnumber).PHP_EOL, FILE_APPEND);
the PHP_EOL constant makes sure to use the right line ending on mac, windows and unix systems the trim function removes any newline or whitespace on both sides of the string. converting to integer would be a huge mistake because 1. you might end up having zero, expecially because of white space or special characters (wherever they come from...) 2. ids dont necessarily need to be integers