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 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 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. 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 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. 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 :) 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??? 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 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
Archived
This topic is now archived and is closed to further replies.