0

我正在创建自动电子邮件回复,但我不想在回复中显示原始电子邮件。电子邮件中有一行必须在上面回复。但是电子邮件程序会在此行之前添加一行,例如“2012 年 8 月 21 日,晚上 11:30,大卫写道:”。

我正在使用此代码将响应分成两部分。它只是无法正常工作。

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

它正在拆分的电子邮件正文是

test from user back again

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

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

我想要做的是在 --- ABOVE THIS LINE --- 位上方的内容处拆分。换句话说,我想删除“On Wed, Aug 22...”这一行。我认为并非所有的电子邮件程序都设置了这条线,如果它们这样做了,它们的做法会有所不同。在此示例中,电子邮件程序实际上也添加了一个空行。

4

1 回答 1

0

干得好!

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

和解释:

# ^.*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 ---»
于 2013-03-13T11:22:40.320 回答