I’m having a little trouble figuring out the pattern to identify the beginning of inline replies/forwards in an email body, there are some easier ones that simply begin with something like “Begin forwarded message” but the replies are a little more complicated:
On 12-06-13 10:56 AM, "John Doe" <john.doe@some.tld> wrote:
Obviously the constants will be “On” and “wrote:”. I’d like to be able to find only the first match and then either wrap everything after it in a div with display:none applied or even just eliminate it using substr($body,0, POSITION_OF_MATCH).
One of the issues I’m having is that it’s not catching the FIRST occurrence, and second is that I can’t get the greediness to work properly.
My progress (having fallen back to at least a partially working version) so far is:
preg_match("/On [^>]* wrote:/i",$content,$matches,PREG_OFFSET_CAPTURE);
Any help would be greatly appreciated!
I appreciate the other answers, but none of them really took into account the many possible variations in the reply strings I was dealing with, that might have been my fault for not explaining properly or providing more options. I’ve +1’d everyone for their efforts though.
The final solution which seems to be working best after a day of fiddling with it on and off is this:
The option list that it begins with covers a range of different reply types that start with “On Tue…” or “On 23…” or “On 1…”, etc. ensuring that the greediness I was complaining about wasn’t taking in too much from random “on” strings elsewhere, the (.*?) takes care of the rest of the name/email portion, finally following up with “wrote:” to finish it off.