Amir Amir - 1 year ago 66
PHP Question

Making a linebreak in text file

i want to save every username in newline
i want text file to look like this :

  • name1

  • name2

instead of this :


PHP code :

$username= $_POST['username']

Answer Source
$username = "\n".$_POST['username'];
file_put_contents("users.txt",$username, FILE_APPEND);

since you seemingly write at the end of the existing file, you have to prepend a linebreak to it.

on a side note: you should always be very careful when processing unfiltered user data.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download