Jump to content

PHP Scrit to compare a file with a string


strategos

Recommended Posts

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! :)

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?

 

 

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.

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.

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.

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.