TedCopple Posted February 17, 2011 Share Posted February 17, 2011 Hello, I am very new to php and I am having a bit of an issue here. I have made a script witch uses _GET to grab a couple of variables from a C++ program I have made. The script then sends those variables to a "log" file in the same directory as the script. Later on I use those variables in my C++ app to read version info ect..(work in progress). For now just to get me started, I will just want to log those variables to the file on the server. My script works perfectly as it is with one annoying flaw: There is no check to see if the entry already exists in the log. I want to do a simple check to read all entries in the file, and then strcmp($VariableFrom_GET, $ALLENTRIESINFILE) != 0, then fwrite the new value. What I can't figure is how to save all entries from the file into an array to compare with the new string. Thanks for any help. Link to comment https://forums.phpfreaks.com/topic/227936-simple-strcmp-help/ Share on other sites More sharing options...
Pikachu2000 Posted February 17, 2011 Share Posted February 17, 2011 If they're separated with new lines, you can read the file directly into an array with file, then you *should* be able to use in_array rather than having to loop through it with strcmp. Link to comment https://forums.phpfreaks.com/topic/227936-simple-strcmp-help/#findComment-1175396 Share on other sites More sharing options...
TedCopple Posted February 17, 2011 Author Share Posted February 17, 2011 If they're separated with new lines, you can read the file directly into an array with file, then you *should* be able to use in_array rather than having to loop through it with strcmp. Alright, I would be happy with that. How can I make sure each new entry is separated with a new line? Also, how would I then utilize "in_array"? -> Nevermind I found an example: if (in_array("mac", $os)) Link to comment https://forums.phpfreaks.com/topic/227936-simple-strcmp-help/#findComment-1175401 Share on other sites More sharing options...
TedCopple Posted February 17, 2011 Author Share Posted February 17, 2011 sorry to double post, but here is what I tried: This should only log the values if it is already detected in the log right? <? $KR = $_GET['test']; $f=fopen("testlog",'a'); $a=file('testlog'); if(in_array($KR, $a)); { fwrite($f,$_GET['test'].' '.$_GET['test2']."\r\n"); } fclose($f); ?> Before I added the "in_array" attempt this is how my log outputs: Testing MyLog My C++ app outputs 2 chars: char* tesing1 = "Testing"; char* testing2 = "MyLog"; Link to comment https://forums.phpfreaks.com/topic/227936-simple-strcmp-help/#findComment-1175408 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.