Jump to content

[SOLVED] Parsing out text file


AV1611

Recommended Posts

I have a text file I retrieve from a vendor

I have to parse it out so I can import it into mysql

I know how to parse the lines to make the records ok, but at the top of the file there are some lines that I don't need and I'm not sure how to parse them out...

here is a mockup of that file the header looks kinda like this:

;--------------
blah blah blah
crap crap
junk junk junk
;--------------
record 1 read data a
record 2 read data b
record 3 read data c

how do I drop the stuff between and including the ;-------'s ???

Thanks
Link to comment
https://forums.phpfreaks.com/topic/31110-solved-parsing-out-text-file/
Share on other sites

[quote author=Orio link=topic=119118.msg487377#msg487377 date=1166457135]
[code]preg_replace("/;[-]+.*?;[-]+/is", "", $text);[/code]
[/quote]

There's no need for the [color=red]i[/color] modifier.  There's no text in the RegEx, so case sensitivity doesn't come into the equation really.

[code]preg_replace("/;[-]+.*?;[-]+/s", "", $text);[/code]

Regards
Huggie
[quote author=HuggieBear link=topic=119118.msg487375#msg487375 date=1166457003]
Is it a varying length or is it always the top 5 lines?

Regards
Huggie
[/quote]

actually, come to think of it, it is just the top 5 lines... I guess I just make a counter on the row and ignore the rows???

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.