[英]detect plain text or html
In my application I am processing mail texts using PHP. 在我的应用程序中,我正在使用PHP处理邮件文本。 For some mail clients such as sina.com is sending bad headers.
对于某些邮件客户端(例如sina.com),发送的标头不正确。 For example, they are sending HTML mail but sending the header Content-Type as text/plain.
例如,他们正在发送HTML邮件,但将标题Content-Type作为文本/纯文本发送。
Now, for these mails, my application is considering the HTML as text. 现在,对于这些邮件,我的应用程序正在考虑将HTML作为文本。 In PHP how can I detect if a text contain html text or not?
在PHP中,如何检测文本是否包含html文本?
是的,您可以使用strip_tags()
并将经过过滤的邮件正文与原始邮件进行比较,以查看是否存在差异,但是请不要忘记,在纯文本中,您可能会将HTML标签作为普通文本,并且我认为strip_tags()
将删除这些标签。
preg_match('/\<html\>(.*)\<\/html\>/', $emailbody)
如果匹配,则为HTML。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.