Jump to content

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???
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.