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

标签 php html regex codeigniter

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

相关文章:

javascript - 具有径向渐变填充的 Highcharts 蜘蛛图未居中

php - 通过 Regex 查找带有第二个参数的所有函数

javascript - 如何在我的 javascripts 中找到站点基本 URL?

php - 使用 Bitbucket 在 Azure 上部署错误(ssh : connect to host bitbucket. org 端口 22:文件号错误)

javascript - 通过 javascript 将 <text> 附加到 <svg>

javascript - 如何使用此脚本创建多个插入文本区域的按钮

javascript - 根据 Laravel 中未定义的父 ID 获取 ajax 下拉列表

javascript - Laravel 广播 : private channels not working due to auth error

android - 如何搜索搜索字符串中的任何字符?

java - 在 Java 中删除标点符号前的空格