TripleDES Posted July 2, 2007 Share Posted July 2, 2007 All, What's the best way to go about parsing through a file and only writing lines that come after x and stop when y is reached? Example: -- Begin X -- We are constantly trying to improve phpfreaks and these forums -- End Y -- Quote Link to comment Share on other sites More sharing options...
corbin Posted July 2, 2007 Share Posted July 2, 2007 I would do it with a regular expression.... maybe something like: //edit: this code doesnt work... ;p The output would be the text without the begin x and end y lines. (P.S. I didn't test that, so if it doesn't work, sorry ;p) Quote Link to comment Share on other sites More sharing options...
effigy Posted July 2, 2007 Share Posted July 2, 2007 How big is/are the file/files? Quote Link to comment Share on other sites More sharing options...
corbin Posted July 2, 2007 Share Posted July 2, 2007 Ahh found a regular expression that works! <?php $content = "-- Begin X -- We are constantly trying to improve phpfreaks and these forums -- End Y --"; $pattern = "/-- Begin ([a-z]+) --(.*)-- End ([a-z]+) --/si"; //$pattern = "/\-\- Begin ([a-z]+) \-\-(.*) \-\- End ([a-z]+) \-\-/si"; preg_match($pattern, $content, $matches); //echo $matches[1]; echo '<pre>'; print_r($matches); echo '</pre>'; /* Output: Array ( [0] => -- Begin X -- We are constantly trying to improve phpfreaks and these forums -- End Y -- [1] => X [2] => We are constantly trying to improve phpfreaks and these forums [3] => Y ) */ ?> Quote Link to comment Share on other sites More sharing options...
TripleDES Posted July 3, 2007 Author Share Posted July 3, 2007 $pattern = "/-- Begin ([a-z]+) --(.*)-- End ([a-z]+) --/si"; Wow...that regex is too complicated for me to understand. Please explain it to me so I can learn. The file is not very big. It's simply a mime encoded email that I'm trying to parse out the message body (text) so I can forward it via SMS. If there's a better way to go about it, please enlighten me. X = --mimepart_...... body...text...etc.... Y = --- Quote Link to comment 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.