Jump to content

No idea what I'm doing


Asheeown

Recommended Posts

Okay, so I'm trying to attempt to parse a configuration file for a program I'm using.  Basically I'm going to end up parsing it and allowing a user to edit it, write it and download the finished file.

 

Each line represents an item that has directives within.  The directives are encased in []'s, they then have an operator (i.e. >=, ==, <=, etc) followed by the value for that operator.  Seems easy at first but some of them have hard balls thrown in there, such as directives located within brackets to indicate a group.

 

Here are some examples:

[Type]==Boots&&[Quality]==rare#[FRW]>=30&&(([FHR]==10&&[Dexterity]>=9)||[itemMagicBonus]>=25||[itemGoldBonus]>=80)&&([ColdResist]+[LightResist]+[FireResist]+[PoisonResist]>=90||([MaxMana]>=35&&[ColdResist]+[LightResist]+[FireResist]+[PoisonResist]>=70))

 

[Type]==Gloves&&[Quality]==rare#[iAS]==20&&[bowandCrossbowSkillTab]==2&&[LifeLeech]>=3&&[ManaLeech]>=3

 

The first one is one of the harder ones, the second one I already can do for the most part.  Directives that have + signs in between them are linked instead of using && operators to define all of them.

 

This is the code I have currently:

$handle = @fopen("Everything.NIP", "r");

if ($handle) {
   while (!feof($handle)) {
       $lines[] = fgets($handle, 4096);
   }
   fclose($handle);
}
$i=1;
foreach($lines as $x) {
$x = str_replace(' ', '', $x);
$Line = explode("#", $x);

$Base = $Line[0];
$Extra = $Line[1];


// Calc base stats
echo "<br>";
preg_match_all('/\[(.*?)\](.*?)(.*?)/si', $Base, $nvhost_matches);
echo "$i Base Stats:<br>";
	foreach($nvhost_matches[3] as $m) {
		echo "$m<br>";
	}

preg_match_all('/\[(.*?)\](.*?)(.*?)/si', $Extra, $nvhost_matches);
echo "$i Extra Stats:<br>";
	foreach($nvhost_matches[3] as $m) {
		echo "$m<br>";
	}
echo "$x<br><br>";
$i++;

}

 

It doesn't even work right now since I extract all the spaces in the string.  The spacing is screwed up in the config file so I figured it'd be easier to strip it and parse everything without spaces.

 

Any help at all would be appreciated.

Link to comment
https://forums.phpfreaks.com/topic/197777-no-idea-what-im-doing/
Share on other sites

Alright let me focus on my main problem since I probably was too vague with my question.

 

If I have a string like this

 

[Type]==Boots&&[Quality]==rare#[FRW]>=30&&(([FHR]==10&&[Dexterity]>=9)||[itemMagicBonus]>=25||[itemGoldBonus]>=80)

 

The first three directives with operators and values I can pull out so it would look like this:

 

Base:

Type == Boots

Quality == rare

Extra:

FRW >= 30

 

Now as it gets to the enclosed groups, that's where I am stuck.

 

I need

(([FHR]==10&&[Dexterity]>=9)||[itemMagicBonus]>=25||[itemGoldBonus]>=80)

 

To be:

Group 1:

    Subgroup 1:

    FHR == 10

    Dexterity >= 9

and (substituting for || operator)

ItemMagicBonus >= 25

and

ItemGoldBonus >= 80

 

I'm trying to get the full group which is the overall statement enclosed in ()s and then subgroups also enclosed in ()s.

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.