strategos Posted January 15, 2012 Share Posted January 15, 2012 Hi, I am relatively new to PHP, and I am making a php script that will FTP into a server and add a donator's ID to a text file. However, I need it to check and see if the user is already listed under a usergroup in that file, and if so, remove those lines of text. Here's an example of what values in the file look like. Basically, I don't know how I could compare the contents of the file and delete it or replace parts of it when necessary "STEAM_0:0:33358541" { "deny" { } "group" "moderator" "name" "TR Cpt. K. Reese" "allow" { } } Also, notice the "deny"{} and "allow"{} These are used for storing special commands that you allow or disallow the user to have in a game. How would i get a PHP script to ignore that... This uses STEAM's framework for userids. All help is appreciated!! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/255050-php-scrit-to-compare-a-file-with-a-string/ Share on other sites More sharing options...
SergeiSS Posted January 15, 2012 Share Posted January 15, 2012 Your question is common that's why the first answer (set of answers) would be common also. First, you have to create a structure inside PHP which is equivalent to your data. This is the main. You may use class(es) to do it. Second, about data. In your example "allow" is related to "TR Cpt. K. Reese" from "moderator" group - is it true? What about "deny" - is it related to this or other user? And what about data concerning to other users? How are they structured? Quote Link to comment https://forums.phpfreaks.com/topic/255050-php-scrit-to-compare-a-file-with-a-string/#findComment-1307794 Share on other sites More sharing options...
laffin Posted January 15, 2012 Share Posted January 15, 2012 My question is in regards to using FTP to update the file, instead of a local file or a database. with a ftp u will have to make a remote connection, grab the file, update the file, and upload it back. Even a php script on the ftp server would be better utilized. Quote Link to comment https://forums.phpfreaks.com/topic/255050-php-scrit-to-compare-a-file-with-a-string/#findComment-1307806 Share on other sites More sharing options...
strategos Posted January 15, 2012 Author Share Posted January 15, 2012 This is for a donation mod for a game server where as the only ports I can use are 21 and the game port. I can't upload php files directly to the sv and they couldn't be accessed anyways. The deny and allow in the example are relative to the user. It stores commands that are explicity allowed or denied to the user therefore, they change per user. Quote Link to comment https://forums.phpfreaks.com/topic/255050-php-scrit-to-compare-a-file-with-a-string/#findComment-1307916 Share on other sites More sharing options...
jcbones Posted January 15, 2012 Share Posted January 15, 2012 FTP inside of PHP Quote Link to comment https://forums.phpfreaks.com/topic/255050-php-scrit-to-compare-a-file-with-a-string/#findComment-1307923 Share on other sites More sharing options...
strategos Posted January 15, 2012 Author Share Posted January 15, 2012 I know how to get it to ftp and write to the file. However, I don't know how to get it to check the file for an existing id, and if ir exists, compare the usergroup and change it from say moderator to donator Quote Link to comment https://forums.phpfreaks.com/topic/255050-php-scrit-to-compare-a-file-with-a-string/#findComment-1307928 Share on other sites More sharing options...
imperialized Posted January 15, 2012 Share Posted January 15, 2012 This is just a suggestion but I do believe it may point you in the right direction. After you download the file from your FTP: $lines = file('your_text_file.txt'); // Loop through our array foreach ($lines as $line_num => $line) { //use a ereg to search for a certain user/setting -- replace if necessary } I am not really familiar with ereg or I would try to help more.. maybe someone else can build on this if it will get you going to the right place. Quote Link to comment https://forums.phpfreaks.com/topic/255050-php-scrit-to-compare-a-file-with-a-string/#findComment-1307930 Share on other sites More sharing options...
strategos Posted January 16, 2012 Author Share Posted January 16, 2012 The $line_num isn't defined Quote Link to comment https://forums.phpfreaks.com/topic/255050-php-scrit-to-compare-a-file-with-a-string/#findComment-1308017 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.