Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-21-2003, 03:46 AM   PM User | #1
mathewvp
New Coder

 
Join Date: Jul 2003
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
mathewvp is an unknown quantity at this point
Regex parsing

I have a text database file which has entries like

//--First Record

|:010 Keyword1:itsvalue
:020 Keyword2:anothervalue
:030 Keyword3:thirdvalue
.......
......
....
:500 Keyword500:somevalue

//Second Record
|:0610 Keyword1:value
......
Records are separated by the "|" symbol(OR)

How do I parse it so that I can separate each record and take the keyword's values

Keywords and values are like "LOCATION:someplace","EMPLOYEE:contract" etc.
Each line starts with a :linenumber and also the data will have : like for website address (http://)


Can anybody help please?
mathewvp is offline   Reply With Quote
Old 11-21-2003, 06:57 PM   PM User | #2
firepages
Super Moderator


 
Join Date: May 2002
Location: Perth Australia
Posts: 3,904
Thanks: 5
Thanked 79 Times in 78 Posts
firepages will become famous soon enough
ouch thats a nasty format , are you stuck with it ? , perhaps better to change the storage format if possible or is that not an option ?

its parsable but avoiding regex is always optimal... how big are the individual files ?
__________________
resistance is...

MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)
firepages is offline   Reply With Quote
Old 11-22-2003, 03:44 AM   PM User | #3
mathewvp
New Coder

 
Join Date: Jul 2003
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
mathewvp is an unknown quantity at this point
Changing the format is not an option coz the file is supplied by somebody else and I have to work on the file.Each record consists of around 100 fields and the total file db size around 15mb
mathewvp is offline   Reply With Quote
Old 11-22-2003, 10:11 AM   PM User | #4
missing-score
Senior Coder


 
missing-score's Avatar
 
Join Date: Jan 2003
Location: UK
Posts: 2,194
Thanks: 0
Thanked 0 Times in 0 Posts
missing-score is on a distinguished road


While it would be possible, it could take a long long time to work with 15 megs of text. Reading the file would take a while, then you would have to split it. While it's possible its highly unpractical. unless you only need to do it once?
missing-score is offline   Reply With Quote
Old 11-24-2003, 03:47 AM   PM User | #5
mathewvp
New Coder

 
Join Date: Jul 2003
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
mathewvp is an unknown quantity at this point
I have already split each record to individual files.I was looking for some code to teach me how to parse through the records.Thanks for the suggestions
mathewvp is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:04 PM.


Advertisement
Log in to turn off these ads.