Looking for some PHP help

TurnX

Senior member
Jan 19, 2006
677
0
76
okay, so I have this text file that is full of character data, heres an example of what the file looks like:

myProfile = {
["Khaz Modan"] = {
["Tenchu"] = {
["Note"] = "",
["Zone"] = "Elwynn Forest",
["Group"] = "mario make me some bags now!>",
["Class"] = "Rogue",
["Online"] = "",
["RankIndex"] = 9,
["Level"] = 8,
["LastOnline"] = 11,
["Name"] = "Tenchu",
["Rank"] = "Officer Alts",
},
["Ainhin"] = {
["Note"] = "",
["Zone"] = "Elwynn Forest",
["Group"] = "",
["Class"] = "Paladin",
["Online"] = "",
["RankIndex"] = 7,
["Level"] = 15,
["Name"] = "Ainhin",
["Rank"] = "Initiate",
},
["Myrios"] = {
["Note"] = "",
["Zone"] = "Ironforge",
["Group"] = "",
["Class"] = "Mage",
["Online"] = "",
["RankIndex"] = 8,
["Level"] = 5,
["LastOnline"] = 14,
["Name"] = "Myrios",
["Rank"] = "Peon",
},
*
*
*
*
*
["Moonshade"] = {
["Note"] = "",
["Zone"] = "Darnassus",
["Group"] = "",
["Class"] = "Rogue",
["Online"] = "",
["RankIndex"] = 7,
["Level"] = 15,
["LastOnline"] = 4,
["Name"] = "Moonshade",
["Rank"] = "Initiate",
},
},
}

(theres about 80 other entries between the ****)

Pretty much I need a script that will pull 4 things from each character: "Class", "Level", "Name", and "Rank" and then take that data and insert it into a sql table. Now I am pretty familiar with php/sql, its just been a few months and im tired of messing with this and getting no where. Any ideas, comments, or just scripts in general you guys can help me with. thanks in advance.
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
I don't think php is necessarily the best tool, as you don't seem to have any web-related requirements. Of course, if it's what you're most capable with, then maybe that's what it's got to be.

Generally speaking, unless you have a parser written for this stuff already in some other language, perl is probably going to be the ideal one to grab the data. There shouldn't be too much trouble connecting to whatever sort of database you're using.
 

phaxmohdem

Golden Member
Aug 18, 2004
1,839
0
0
www.avxmedia.com
yeah, I"m with kamper on this one, I'm just not sure that php is the ideal language.

I don't know if php can parse an external text file or not, but if it can, you could:

- Load the text file to convert/parse
- use substrings/tokens to search for the information string you want to pull
- save the information to a variable
- test that all four variables contain a value
- if no go to next token and grab the next bit of data/save it to its variable
- if yes, sql command to save to your db, then clear variables out

Something like that. Like I said, I've never done anything like that with PHP.
 

TurnX

Senior member
Jan 19, 2006
677
0
76
well im not to familliar with pearl at all, so if you guys think that would be the best solution is there any guide or anything you guys could suggest to help me out?
 

phaxmohdem

Golden Member
Aug 18, 2004
1,839
0
0
www.avxmedia.com
Out of curiosity, is this script for a one time conversion of your text file? or will it be used ongoingly? If this is a one time use thing 80 or so characters is not that many, and it may just be easier to enter them into your DB by hand and let a php script handle it automaticaly in the future... of course you're not learning much that way..

Here's some good bathroom reading on Perl: http://www.comp.leeds.ac.uk/Perl/start.html