AV1611 Posted December 18, 2006 Share Posted December 18, 2006 I have a text file I retrieve from a vendorI 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 blahcrap crapjunk junk junk;--------------record 1 read data arecord 2 read data brecord 3 read data chow do I drop the stuff between and including the ;-------'s ???Thanks Quote Link to comment https://forums.phpfreaks.com/topic/31110-solved-parsing-out-text-file/ Share on other sites More sharing options...
HuggieBear Posted December 18, 2006 Share Posted December 18, 2006 Is it a varying length or is it always the top 5 lines?RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/31110-solved-parsing-out-text-file/#findComment-143655 Share on other sites More sharing options...
Orio Posted December 18, 2006 Share Posted December 18, 2006 [code]preg_replace("/;[-]+.*?;[-]+/is", "", $text);[/code]Orio. Quote Link to comment https://forums.phpfreaks.com/topic/31110-solved-parsing-out-text-file/#findComment-143657 Share on other sites More sharing options...
HuggieBear Posted December 18, 2006 Share Posted December 18, 2006 [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]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/31110-solved-parsing-out-text-file/#findComment-143662 Share on other sites More sharing options...
Orio Posted December 18, 2006 Share Posted December 18, 2006 I automaticly add it, it doesnt make a diffrence in this case... (that I know of :))Orio. Quote Link to comment https://forums.phpfreaks.com/topic/31110-solved-parsing-out-text-file/#findComment-143665 Share on other sites More sharing options...
HuggieBear Posted December 18, 2006 Share Posted December 18, 2006 [quote author=Orio link=topic=119118.msg487385#msg487385 date=1166457502]it doesnt make a diffrence in this case...Orio.[/quote]Pun totally intended :) Quote Link to comment https://forums.phpfreaks.com/topic/31110-solved-parsing-out-text-file/#findComment-143671 Share on other sites More sharing options...
AV1611 Posted December 18, 2006 Author Share Posted December 18, 2006 [quote author=HuggieBear link=topic=119118.msg487375#msg487375 date=1166457003]Is it a varying length or is it always the top 5 lines?RegardsHuggie[/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??? Quote Link to comment https://forums.phpfreaks.com/topic/31110-solved-parsing-out-text-file/#findComment-143699 Share on other sites More sharing options...
HuggieBear Posted December 18, 2006 Share Posted December 18, 2006 You could, but if the comments are always delimited by the ;---- then the RegEx that Orio suggested would probably be better, if it's coming from an external source, which it is, the RegEx is possibly more reliable.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/31110-solved-parsing-out-text-file/#findComment-143703 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.