n00b parsing text file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Acekiller
Forum Newbie
Posts: 3
Joined: Mon Aug 10, 2009 2:19 pm

n00b parsing text file

Post by Acekiller »

I am not really a CS person, but I have a task to import a non-delimited text to an access database. After some research, I *think* the best way to do this is by first converting the non-delimited text to delimited text, and then import it to the database.

thus I need to write a parser and use something as delimiters (I am thinking of a |)

An example of the text file is posted at http://pastebin.com/f4e0ef4ba

Line 1 is useless, so the program would start at line 2.

Basically, from line 2 to 8 contains a person's standard information, starting in line 9, custom comments/info are placed in the <tags>. After the last tag <stop_com>, another person's standard information would come up in the first 7 lines, and then the tags would repeat.

Ultimately, I need to get the text to convert to something that looks like this.
last name | First name| Medical num | birth date| sex| ID | blood grp| phenotype| TR| AB| AG| Comment| ...


Any help on getting me started on this is appreciated. I know how php works, but is very very limited in the actual programming...
infiniteacuity
Forum Newbie
Posts: 12
Joined: Tue Jun 16, 2009 2:48 pm
Location: Ft. Lauderdale

Re: n00b parsing text file

Post by infiniteacuity »

How are you getting the data? As a text file, XML feed or some other method?
Acekiller
Forum Newbie
Posts: 3
Joined: Mon Aug 10, 2009 2:19 pm

Re: n00b parsing text file

Post by Acekiller »

it is a text file, like the one shown in the link.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: n00b parsing text file

Post by califdon »

To write a script to parse such a file isn't that hard, conceptually, but to do so with error trapping to handle anomalies and provide useful data is a pretty ambitious project for an inexperienced programmer. I recommend you have this done by someone who knows how to do it. Believe me, it will cost your organization less than the time you will spend trying to seek help and get something up and running correctly.
Post Reply