Hi all.

I have an application were a user fitt (outside the game) a "ship" and after the full fitt he can save that in a doc file.

In that file we'll see 4 fields with vari lines in each of them (not the same fitt for all the ships).

I want to create a form where you paste the entire content of the file and submit. That will be placed in mysql database. There is a page were the users can search a ship and he will see all the fittings availble for the ship he selected on a webpage.

Can anyone help me get this thing going ?

Would be much apriciated if someone could help me.

Example of the file:

Item 1 Low Slot
Item 2 Low Slot
Item 3 Low Slot

Item 1 Med Slot
Item 2 Med Slot
Item 3 Med Slot
Item 4 Med Slot

Item 1 High Slot
Item 2 High Slot
Item 3 High Slot
Item 4 High Slot
Item 5 High Slot

Item 1 Rig Slot
Item 2 Rig Slot

i think i can help you, but please explain it in more detail. what is a "fitt", maybe fitting i don't know. just please be more clear. what exactly are you trying to do or what are you even saying, "fitt", "full fitt", ????????

Hi Keith

Fitt is for "Fitting".

I play a game were we have ships and need to br fitted with some equipment.
We have a 3party tool that give us the possibility to "test" some fittings (when you drag the modules into the shipp it gives the stats of battle and ship endurance).

After fitting you can copy the fitting and paste were ever you want.
I would like to make a page so the members of my corp can share some info.

1 - They would paste the info in some kind of form and when submited it drops the info in a mysql;
2 - In a search page they will get a result according to their needs.

all of that is not hard, and will only take maybe an hour. what i need from you: mysql table name, fields of that table. Also, what exactly are they going to be putting into the database. just show an example thats all i need.

Medium Armor Repairer II
Reactor Control Unit II
Power Diagnostic System II
Adaptive Nano Plating II
Reactor Control Unit II

Cap Recharger II
Cap Recharger II
Cap Recharger II

Medium Nosferatu II
Medium Nosferatu II
Medium Nosferatu II
Medium Nosferatu II

Anti-Thermic Pump II
Anti-Kinetic Pump II

_____________________

This is one example of a fitting created in the program. This is what I'v got to copy/paste.
The first 5 lines represent the low-slot of the ship, the next 3 the mid-slot, the other 4 are the high-slot and the last 2 are the rig-slot.
The number of lines per slot are diferent from ship to ship.

The user should copy the file (like the one above) and paste it to a form, he also need to give a name to the fitting (on another field).

The field of the table should be something like:

ID;
Ship; (this one the real name of the ship from the game)
Fitting;
Date; (optional)

Member Avatar for iamthwee

All this is, is basic parsing of information and separating it into their relevant fields. What don't you get?

All this is, is basic parsing of information and separating it into their relevant fields. What don't you get?

I know that is just parsing. The problem is that the text don't have fixed fields.
The text change from fitting to fitting, ex:

Fitting 1:

Medium Armor Repairer II
Reactor Control Unit II
Power Diagnostic System II

Cap Recharger II
Cap Recharger II

Medium Nosferatu II
Medium Nosferatu II
Medium Nosferatu II

[empty rig slot]

Fitting 2:

Medium Armor Repairer II
1600mm Reinforced Titanium Plates I
Energized Basic Adaptive Nano Plating
Magnetic Field Stabilizer II
Partial Power Plant Manager: Capacity Power Relay
Type-D Power Core Modification: Capacitor Power Relay

Heavy Capacitor Booster II
Sensor Booster II
Magnetic Scattering Amplifier II
100MN Afterburner II

[empty high slot]
Neutron Blaster Cannon II
Neutron Blaster Cannon II
Neutron Blaster Cannon II
Neutron Blaster Cannon II
Neutron Blaster Cannon II

[empty rig slot]
[empty rig slot]

As you can see I have here 2 diferent fittings for 2 diferent ships. How can I parse this?

What you'd have to do is make sure the patterns exist for each input file (they don't have to be strict patterns, just a standard format) and then parse your files off of that. If you don't have any patterns to match, you've got a situation where you're trying to do human-level comprehension. That's way beyond the average PHP program.

As you can see in my last post, none of the previous texts had a fixed line.
Each line represents a item and each blank line represents a change in the type of slot used.

I know that this is difficult to do. My hope was that I could parse the text to use a DB, that I have, of the items.

Take a moment and look at what will always be the same in your file.
1. Are the "fittings" from a standard set?
2. Is each blank line guaranteed to be there?
2a. What about line endings? (Does an EOL mean end of item slot?)
3. Can "fittings" go in a different place on your "vessel" or are they one position only?
3a. If they can go multiple places, does the order of the list matter?

Take a moment and look at what will always be the same in your file.
1. Are the "fittings" from a standard set?
2. Is each blank line guaranteed to be there?
2a. What about line endings? (Does an EOL mean end of item slot?)
3. Can "fittings" go in a different place on your "vessel" or are they one position only?
3a. If they can go multiple places, does the order of the list matter?

1. The fittings are the selections of playes from a data base of >1000 items
2. yep. Each blank line sets the next slot
2a. as above
3. Each ship has ALWAYS 4 slots. High, med, low and rig slots, but the player doesn't have to use them all (there are a lot of crazy people in the game :))
3a. Ther order of the slots in the file is, Low - Med - High - Rig (always).

Ok, now that I understand how your file is set up, I can offer some advice:

Your file relies on line endings and blank lines to seperate data. By looking for them and taking everything from the previous EOL+1 (end of line) to the current EOL you've got your item. (This is a string-centric view.)

Reading in a file makes this process easy. As you read each line, you'll have your items, or an EOL character. You can then do as you wish with the item (you may need to chop() it first) such as compare it to a list of items appropriate to the slot you're reading, or simply adding it to the appropriate place in the database. If it's an EOL, don't worry. The database accepts NULL values (unless someone used the NOT NULL option.)

Why don't you try it and see if you can do it now?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.