I'm working on a PHP ticket system where I pipe emails, grab their HTML and insert into database.
I've added this line to my outgoing emails:
## If you reply, text above this line is added to the request ##
Saw this type of thing in an Upwork email and it was easy enough grab only the email/html BEFORE that unique string, using:
//now, get only the stuff before our "dividing" line starts
$html = strstr($html, '## If', true) ?: $html;
Anyway, I've noticed Gmail adds the following automatically to all email replies:
On Fri, Jun 7, 2019 at 2:40 PM Carson Wentz<[email protected]> wrote:
So after I do step one to only keep things before "## If you reply...," I now would like to search the remaining text/html to see if it has a string starting with "On" and ending with "wrote:". And if so, only grab the stuff before that (similar to step 1).
I'm having trouble finding anything clearly explaining how to search a longer string for a shorter string that BEGINS WITH something AND ENDS WITH something specific, regardless of what's in the middle. I imagine it would have to use REGEX?
However, as I write this, I just realized that it's pretty likely that at some point someone might start their reply with "On" in which case EVERYTHING would be removed. Ugh.
If anyone has any ideas if this can be handled, please let me know. More I think about it, I might just have to have that Gmail-included line appear in all replies within the ticket system since I don't think there's an absolute way I can get that exact string, since it includes date/time and Name info that obviously is always different.
Thanks for your time.
On Fri, Jun 7, 2019as the intro to a sentence which makes even stricter regex wrong. Maybe start withOn [A-Z][a-z]{2}, [A-Z][a-z]{2} \d{1,2}, \d{4} at \d?\d:\d?\d [AP]M [A-Za-z]+ [A-Za-z]+<.*?> wrote:Change the[A-Z][a-z]{2}to a optional group with day abbrevs. Then do the same for months. Change the\d{1,2}` to valid minutes, hours.