Jump to content

Parsing File and Printing Only Certain Lines


TripleDES

Recommended Posts

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
)

*/
?>

$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 = ---

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.