fwrite - need a new line after variable - PHP
<p>When my script writes to the file, it doesn't break the added content onto a new line.  </p>

<pre><code>Instead of:
user1:password1
user2:password2

It writes:
user1:password1user2:password2
</code></pre>

<p>Originally, my fwrite looked like this fwrite($fh, $data); and from searching other questions, I changed my code to this:</p>

<pre><code>fwrite($fh, $data . "\n"); 
</code></pre>

<p>This does not seem to work though.  </p>

<p>Here is my code</p>

<pre><code>&lt;?php

if (isset($_POST['submit'])) 
{ 

$username = $_POST['user'];
$password = $_POST['password'];
$confirmpw = $_POST['confirmpw'];
$username = strtolower($username);


//Check if passwords match
if ($password != $confirmpw){
print "Passwords do not match, please try again.";
}
else{
//the data
$data = "$username:$password\n";

//open the file and choose the mode

$fh = fopen("passwd.txt", "a+");

// Cycle through the array
$match_found = false;

while (($buffer = fgets($fh, 4096)) !== false)
{
// Parse the line
list($usercheck, $passwordcheck) = explode(':', $buffer);
if (trim($usercheck) == $username)
{
    print "The username is already in our system.  Please use another one.";
    $match_found = true;
    break;
}
}

if(!$match_found)
{
fwrite($fh, $data . "\n");
// Set cookies for an hour
$hour = time() + 3600;
setcookie("username", $username, $hour);
//Redirect to home page
header("location: index.php");
}


}
//close the file

fclose($fh);


}


?&gt;
</code></pre>
