gpt4 book ai didi

php - 检查电子邮件内容是纯文本还是 HTML - PHP

转载 作者:搜寻专家 更新时间:2023-10-31 21:07:22 25 4
gpt4 key购买 nike

在 Code Igniter 框架上工作,我正在使用 Peeker 检索电子邮件library.Sometimes I don't recieve the HTML内容,只是plain text的电子邮件。对于纯文本,我想替换 \r\n<br>但不适用于 HTML 内容。我得到以下 function来自 SO检查内容是否为 HTML:

function is_html($string)
{
return preg_match("/<[^<]+>/",$string,$m) != 0;
}

以下是我收到的几条纯文本:

On 5/15/15, Mr.X  wrote:
> Mr. Y,
>
> Congratulations! Your book has been approved by our Editorial Board for
> Publishing. Please send me all the fonts that you have used to type
> your manuscript. Please send me the font names and the font files so that
> we can proceed.......

但函数返回 TRUE也适用于纯文本。如何区分?

最佳答案

因为我知道 <div><table>标签将出现,我对正则表达式进行了以下更改并且它运行良好。

preg_match("/<tr [\s\S]*?<\/tr>|<table [\s\S]*?<\/table>|<div [\s\S]*?<\/div>",$string) != 0;

关于php - 检查电子邮件内容是纯文本还是 HTML - PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30274479/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com