Hi, When running the script given below, while displaying the contents of the file "user_names.txt" I see a space being added at the end of each line. Due to this my condition statement is showing an incorrect result. Could someone please help me to resolve this issue? I have tried running this script on both windows and linux servers. Thanks. -------------------------------- <?php $uid = "user_1"; $uidFile = "user_names.txt"; $uidFileHeader = @fopen($uidFile, 'r'); if ($uidFileHeader) { while (!feof($uidFileHeader)) { $reserved_names = fgets($uidFileHeader); print "res $reserved_names*<P>"; print "uid $uid*<P>"; if ($reserved_names == $uid){ print "Got one<P>"; } } fclose($uidFileHeader); } ?> ------------------------- The output: res user_1 * uid user_1* res user_2 * uid user_1* res user_3 * uid user_1* res * uid user_1* -------------------------- Content of "user_names.txt" user_1 user_2 user_3
Yeah, if you actually view the source of the outputted HTML, you'll probably not see a space before the <p> but in fact a new line (which is converted to a space by browsers). Hence the reason to use trim.
Thanks a lot. It worked. I replaced the line "$reserved_names = fgets($uidFileHeader);" with "$reserved_names = trim(fgets($uidFileHeader));"