php包含头文件,从php中提取包含正文部分的所有邮件头文件

该问题涉及使用PHP从TXT格式的连锁邮件中提取邮件正文和头部信息。提供的正则表达式未能正确提取最后一个条目,因为它依赖于'From:'字段作为分隔符。建议调整正则表达式或采用不同的方法,如根据邮件头部集群分割文档,以确保获取所有内容。同时,讨论了可能的替代方案和对输出格式的需求。
摘要由CSDN通过智能技术生成

我想在php中使用正则表达式从下面的链式邮件中提取正文部分。 连锁邮件以txt格式保存。在提取时,如果在body标签中存在html标签,则应该保持不变。从php中提取包含正文部分的所有邮件头文件

$content = <<

From: Matrimony

Sent: Fri, 12 Aug 2011 16:17:40

To: "[email protected]"

Subject: Re: bride search

From: brides

Sent: Fri, 12 Aug 2011 15:49:52

To: "Matrimony "

Cc: "groom"

Subject: Re: bride search

PFA

Regds.,

sales

From: shaadi

Sent: Tue, 22 Feb 2011 16:40:24

To: ,

Cc: "'lagna '" , , , "'beta data'" , "'test S'"

Subject: Re:data transfer would be made live for 145 test

This is to inform you that we are going to test today.

Activity Timing: 9:00 PM onwards

Thanks and Regards,

free matrimony

shaadi Operations

P Please do not print this e-mail unless it is absolutely necessary

From: shaadi [nikaah:[email protected]]

Sent: 21 February 2011 23:09

To: [email protected]; [email protected]

Cc: 'lagna '; [email protected]; [email protected];

Subject: data transfer would be made live for 145 test

Hi,

gtsdhsdbh

anbdsmbsa

sda the data test .

Would request you to send in your feedback.

Thanks and Regards,

beta data

assa xyz

P Please do not print this e-mail unless it is absolutely necessary

HEREDOC;

O/P

Array

(

[0] => Array

(

[0] => Re: bride search

[1] => Re: bride search

PFA

Regds.,

sales

[2] => Re:data transfer would be made live for 145 test

This is to inform you that we are going to test today.

Activity Timing: 9:00 PM onwards

Thanks and Regards,

free matrimony

shaadi Operations

P Please do not print this e-mail unless it is absolutely necessary

)

[1] => Array

(

[0] => Re: bride search

[1] => Re: bride search

PFA

Regds.,

sales

[2] => Re:data transfer would be made live for 145 test

This is to inform you that we are going to test today.

Activity Timing: 9:00 PM onwards

Thanks and Regards,

free matrimony

shaadi Operations

P Please do not print this e-mail unless it is absolutely necessary

)

)

是我用来获取上述O/P的正则表达式

preg_match_all('/(?<=Subject:)(.*?[\n][\s]*?)(?=From:)/is',$content,$rest);

,但它并没有给出最后的一个,因为它没有 '从'获取中间数据。 希望它清楚。 请让我知道是否也有其他方法,为此。

preg_match_all('/(?m:^From:\x20(?[^\n]*)\n^Sent:\x20(?[^\n]*)\n^To:\x20(?[^\n]*)\n(?:^Cc:\x20(?[^\n]*)\n)?^Subject:\x20(?[^\n]*)\n)(?.*?(?=(?:\nFrom:)|$))/s',$content,$matches);

echo "

".print_r($matches,true);

+0

我不知道如果正则表达式是最好的选择。你最好根据/从/主题数据的“簇”来分割文档。从那里,任何内容都应该被视为内容。 –

+0

你会编辑你的问题,以澄清所需的输出? –

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值