file() and array values contain extra \n

From: Date: Tue, 16 Jul 2002 13:53:33 +0000
Subject: file() and array values contain extra \n
Groups: php.general 
Request: Send a blank email to php-general+get-107864@lists.php.net to get a copy of this message
$users=file('.users'); # puts users in the file into an array so we can # check for valid or priv users with if(in_array($HTTP_SERVER_VARS["REMOTE_USER"], $users)){} # we add additional users to the .users file with the following $users[]=$newuser; # adds the new user to the end of the above created users array # then write the array to the file $fd = fopen (".users", "w+"); fwrite ($fd, join("\n",$users)); fclose ($fd); the problem is after adding users, only the last user returns the user name in the array, all the other users have an additional "/n" at the end of them, which causes the check to barf. I want to ensure that the .users file is in; user1 user2 user3 ...format, am I missing something in the reconstruction of the users file that can eliminate the "\n" being placed into the array on the next file() call? hope that made sense... thank. Dave

« previous php.general (#107864) next »