Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJason Tadlock
14,748 PointsPHP file parsing help
Hey everyone! I'm creating a site for a gaming clan. They would like a web app that allows them to upload a recorded game file from a certain game.
The app would receive the file, parse the data in the file and show certain information on a page from the file(player names, rank before game began, rank after game is over, map they played on, etc.).
Can anyone tell me what I need to learn in order to parse files server side and show the formatted data on a page? The file types are .rcx and .sc2replay.
Jason Tadlock
14,748 PointsJason Tadlock
14,748 PointsThanks! That will help with sc2 files. The .rcx format is the only format the other game uses for recorded games. There is a site(rts-sanctuary) that has a really old web app that parses .rcx files and displays data from the file. Here is a screenshot of the displayed data. This kind of app would be perfect. I would just like to know how they did it so I can start learning the process.
thomascawthorn
22,986 Pointsthomascawthorn
22,986 PointsI haven't been able to find an example of the insides of one of these files, but a parser will run through the output character by character and look for specific matches in the string. If it's a super consistent file, this should be quite easy - like CSV files, you can be almost 100% certain that all the 'good stuff' is going to be placed in a specific number of columns between commas etc...
You're probably going to want to build a nested array structure - I would start there. Try and create the perfect array structure first and then find where all that information exists in the file. If it's semi-keyed already, you could say things like: look for a new score line by matching 'score line' in the file -> inside this score line, look for a string key of 'name' -> grab all the content between the 'name' key and the next key and store it in the appropriate php array.
If it's kind, and by kind I mean super consistant, you might get away with creating one super loop structure that will grab everything over and over again until you hit the end of the file. If it's more complex, you're going to have to add more 'if else' constructs to combat the various scenarios.
Jason Tadlock
14,748 PointsJason Tadlock
14,748 PointsThanks for the great information. So basically, use something like file_get_contents and create an array with the data I need. Any particular courses and/or links that will help me nail down this entire process? I want to build an app that will upload a file, parse the file, display the content how I please, and give them a download option that will will allow others to download the file after it is submitted.
thomascawthorn
22,986 Pointsthomascawthorn
22,986 Pointshmm, I personally couldn't tell you any more than google right now, but I can say you'll probably need a database to store all the data from the uploaded files - it wouldn't be great to continually parse the file for every display because you'll be putting a lot of effort into scanning unnecessary information.
Hope this gets you started :-)
Jason Tadlock
14,748 PointsJason Tadlock
14,748 PointsI found a program called TitanTools that was created for the .NET 1.1 framework. It pulls pretty much all the info I need into a GUI display. Is there anyway I could recreate just the process of decoding the file information like this program does in a PHP environment?