Jump to content

Issues with fgets()


proggR

Recommended Posts

So I'm reading in the first line of a file to compare it with the data I want to add to it and if they match it should return a message saying that the data is already there. But It doesn't seem to happen. It just jumps to my else option and prints the data into the file anyway. So I had it printing my fgets value and aparently its not seeing the /n and its grabbing two pieces of data from the file (which take up the first line when you look in notepad) and so of course that value and my one new piece of data don't match.

Is there any reason for this? I'm on a Windoze machine so would I have to use fopen($file, 'a+t');?

I could just go through and add ."/r/n" "\r\n" instead of ."/n" "\n" to the fwrite since I'm still just testing everything and haven't actually used it on a larger scale yet but I'm writing this on a Windows laptop and will later be uploading it to a Linux server and would rather not write it this way. But is it safe to say that's what's happening here?

 

 

Pee Ess. I've been reading around and I think the general concensus is no, but is there any way to append to the beginning of the file? Like r+ except it doesn't overwrite the data? I'll probably have to read the old data and then rewrite it but I'd rather not if I could avoid it. Thanks.

 

 

 

*edit* made the noob mistake of using the wrong slashes in my OP. Sorry

Link to comment
https://forums.phpfreaks.com/topic/113549-issues-with-fgets/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.