在 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/