0

I'm creating a automatic email response, but I don't want to show the original email in the response. There is a line in the email that they must respond above. But email programs add a line like "On Aug 21, 2012, at 11:30 PM, David wrote:" before this line.

I'm using this code to split the response into two parts. It's just not working correctly.

$parts = preg_split('/([\r|\n].+[\r|\n]>[\r|\n])?(> )?--- ABOVE THIS LINE ---/',$in->body);

The email body that it's splitting is

test from user back again

On Wed, Aug 22, 2012 at 9:55 AM, Support <support@example.com> wrote:

> --- ABOVE THIS LINE ---
>
>   Support Ticket

What I want to do is split at the line with content above the --- ABOVE THIS LINE --- bit. In other words I want to remove the "On Wed, Aug 22..." line. I assume not all email programs put this line and if they do, they do it differently. In this example, the email program is actually adding a blank line as well.

Unamata Sanatarai
  • 6,475
  • 3
  • 29
  • 51
David Fairbanks
  • 638
  • 7
  • 17

1 Answers1

0

here you go!

/^.*wrote:(?s).* --- ABOVE THIS LINE ---/im

and a explanation:

# ^.*wrote:(?s).* --- ABOVE THIS LINE ---
# 
# Options: case insensitive; ^ and $ match at line breaks
# 
# Assert position at the beginning of a line (at beginning of the string or after a line break character) «^»
# Match any single character that is not a line break character «.*»
#    Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
# Match the characters “wrote:” literally «wrote:»
# Match the remainder of the regex with the options: dot matches newline (s) «(?s)»
# Match any single character «.*»
#    Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
# Match the characters “ --- ABOVE THIS LINE ---” literally « --- ABOVE THIS LINE ---»
Unamata Sanatarai
  • 6,475
  • 3
  • 29
  • 51