从电子邮件正文中截取签名的最佳方法

从电子邮件正文中截取签名的最佳方法

本文介绍了从电子邮件正文中截取签名的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在解析一些电子邮件.我认为移动邮件,iPhone和iPod touch会附加一个签名作为单独的边界,从而使其易于删除.并非所有邮件客户端都这样做,仅使用'-'作为签名定界符.

I am parsing out some emails. Mobile Mail, iPhone and I assume iPod touch append a signature as a separate boundary, making it simple to remove. Not all mail clients do, and just use '--' as a signature delimiter.

我需要从字符串中剔除'-',但仅是最后一次出现.

I need to chop off the '--' from a string, but only the last occurrence of it.

样本副本

 hello, this is some email copy-- check this out
 --
 Tom Foolery

我很想在'-'上进行拆分,删​​除最后一部分,我会拥有它,但是explode()和split()似乎都没有返回很大的值,因为如果发生这种情况,让我知道它是否做了任何事情没有匹配项.

I thougth about splitting on '--', removing the last part, and I would have it, but explode() and split() neither seem to return great values for letting me know if it did anything, in the event there is not a match.

我不能让preg_replace跨越多行.我已经将所有行尾都标准化为\ n

I can not get preg_replace to go across more than one line. I have standardized all line endings to \n

以你好,这是一些电子邮件副本-检查出来"结尾的最佳建议是什么,如果没有,最好是在没有签名的情况下,当然在某些情况下我无法涵盖所有​​情况.

What is the best suggestion to end up with "hello, this is some email copy-- check this out", taking not, there will be cases where there is no signature, and there are of course going to be cases where I can not cover all the cases.

推荐答案

我认为,为了更加防弹,我将采用非正则表达式路线

I think in the interest of being more bulletproof, I will take the non regex route

        echo substr($body, 0, strrpos($body, "\n--"));

这篇关于从电子邮件正文中截取签名的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 02:00