Jump to content


Text File Parse


1 reply to this topic

#1 Pax

    P2L Jedi

  • Members
  • PipPipPip
  • 911 posts
  • Gender:Male
  • Location:Windsor, ON, Canada

Posted 03 January 2006 - 11:57 AM

I'm trying to find out if it is possible to take a normal text file and parse it in ColdFusion (or php...will be learning that soon) and pull variables out of it. I'm working on a website for a freind, that will hopefully parse an uploaded text file of a unit after battle. The game is BattleTech based (Mechwarrior games), and when the battle is finished it spits out a big txt file called entitystats.txt. The following is a sample of the code. It starts off with the player name (Lt. Shadrach Smith) then goes on to the model of the mech (Atlas - AS12-X2), the pilot with name and skill, remaining armour, and so on. The next mech skips out on the player name, the rest of the units for hte player Shadrach then follow the same format.

=============================================================
++++++++++ Lt. Shadrach Smith ++++++++++
=============================================================
Model: Atlas - AS12-X2
Pilot: Unnamed (2/4)
--- Armor: 243/307-------------------------------------------
--- Internal: 152/152----------------------------------------
		 FRONT				REAR				INTERNAL
	  .../ 9\...		   .../**\...			.../ 3\...
	 /32| 47 |26\		 /10|  5 |10\		  /21| 31 |21\
	(21). -- .(34)	   (   |	|   )		(17). -- .(17)
	   /  /\  \			 /	  \			  /  /\  \
	  /13.\/.36\		   /		\			/21.\/.21\

-------------------------------------------------------------
Head		: Life Support,Sensors,Cockpit,ER Small Laser,Sensors,Life Support
Center Torso: Engine,Engine,Engine,Gyro,Gyro,Gyro
			  Gyro,Engine,Engine,Engine,Large Pulse Laser,Large Pulse Laser
Right Torso : Engine,Engine,Engine,Gauss Ammo (0),Gauss Ammo (8),Gauss Ammo (8)
			  SRM 4,ER Medium Laser,Double Heat Sink,Double Heat Sink,CASE,Artemis IV FCS
Left Torso  : Engine,Engine,Engine,C3i Computer,C3i Computer,Heavy Medium Laser
			  Heavy Medium Laser,Double Heat Sink,Double Heat Sink,Double Heat Sink,Double Heat Sink,CASE
Right Arm   : Shoulder,Upper Arm,Gauss Rifle,Gauss Rifle,Gauss Rifle,Gauss Rifle
			  Gauss Rifle,Gauss Rifle,SRM 4 Ammo (19),SRM 4 Ammo (25),Double Heat Sink,Double Heat Sink
Left Arm	: Shoulder,Upper Arm,Lower Arm,Hand,Ultra AC/10,Ultra AC/10
			  Ultra AC/10,Ultra AC/10,Ultra AC/10 Ammo (0),Ultra AC/10 Ammo (10),Ultra AC/10 Ammo (10)
Right Leg   : Hip,Upper Leg,Lower Leg,Foot,Double Heat Sink,Double Heat Sink
Left Leg	: Hip,Upper Leg,Lower Leg,Foot,Double Heat Sink,Double Heat Sink
-------------------------------------------------------------
Ultra AC/10 Ammo: 0
Ultra AC/10 Ammo: 10
Ultra AC/10 Ammo: 10
SRM 4 Ammo: 19
SRM 4 Ammo: 25
Gauss Ammo: 0
Gauss Ammo: 8
Gauss Ammo: 8
=============================================================
=============================================================
Model: Thunder Hawk - TDK-7XR
Pilot: Unnamed (2/3)
--- Armor: 177/304-------------------------------------------
--- Internal: 152/152----------------------------------------
		 FRONT				REAR				INTERNAL
	  .../ 4\...		   .../**\...			.../ 3\...
	 /27| 35 |10\		 /10| 15 | 8\		  /21| 31 |21\
	(20). -- .(15)	   (   |	|   )		(17). -- .(17)
	   /  /\  \			 /	  \			  /  /\  \
	  /31.\/. 2\		   /		\			/21.\/.21\

-------------------------------------------------------------
Head		: Life Support,Sensors,Cockpit,+ER Medium Laser,Sensors,Life Support
Center Torso: Engine,Engine,Engine,Gyro,Gyro,Gyro
			  Gyro,Engine,Engine,Engine,Gauss Ammo (8),Gauss Ammo (8)
Right Torso : Engine,Engine,Engine,+Gauss Rifle,+Gauss Rifle,+Gauss Rifle
			  +Gauss Rifle,+Gauss Rifle,+Gauss Rifle,+Gauss Rifle,Gauss Ammo (0),Gauss Ammo (0)
Left Torso  : Engine,Engine,Engine,+Gauss Rifle,+Gauss Rifle,+Gauss Rifle
			  +Gauss Rifle,+Gauss Rifle,+Gauss Rifle,+Gauss Rifle,Gauss Ammo (0),Gauss Ammo (8)
Right Arm   : Shoulder,Upper Arm,Lower Arm,Hand,+Gauss Rifle,+Gauss Rifle
			  +Gauss Rifle,+Gauss Rifle,+Gauss Rifle,+Gauss Rifle,+Gauss Rifle
Left Arm	: Shoulder,Upper Arm,Lower Arm,Hand,+ER Medium Laser
Right Leg   : Hip,Upper Leg,Lower Leg,Foot
Left Leg	: Hip,Upper Leg,Lower Leg,Foot,C3i Computer,C3i Computer
-------------------------------------------------------------
Gauss Ammo: 0
Gauss Ammo: 0
Gauss Ammo: 0
Gauss Ammo: 8
Gauss Ammo: 8
Gauss Ammo: 8
=============================================================
=============================================================

Now, is what I'm trying to do (at not getting anywhere with it) is try to have a user upload their entitystatus.txt file then pull variables from that file and add it to a database to keep track of that users units. I want it to pull the users name, model name, pilot name and skill, armour and internal structure left on the mech and some more stuff like that. Is it at all possible? Is it possible in coldfusion or php? Im hoping this will be possible in coldfusion, as this is (if it works) will be submitted for a project at school.

Thanks for any help available!

Another thing that might work would be if I could convert a .txt into an .xml somehow? Is that possible to have php or coldfusion do that when a user uploads a .txt file?

#2 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 04 January 2006 - 04:22 PM

A txt file like what you posted would be near impossible to parse with out a parser that's more complex then googles search algorithem.
And i don't know anything about coldfusion, but you can look at some of the following PHP functions and see if you can come up with an easier txt file to parse.
http://php.net/manua...se-ini-file.php
http://php.net/manua...n.parse-str.php
http://php.net/manual/en/ref.xml.php

p.s. please don't double post.

Edited by rc69, 04 January 2006 - 04:23 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users