将HTML转换为纯文本的PHP中的电子邮件 [英] Converting HTML to plain text in PHP for e-mail

查看:121
本文介绍了将HTML转换为纯文本的PHP中的电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 TinyMCE ,允许在我的网站内最小化文字格式。从生成的HTML中,我想将其转换为纯文本的电子邮件。我一直在使用一个名为 html2text 的课程,但UTF-8的支持确实缺乏,其他事情。不过,我认为,它将某些HTML标签映射到纯文本格式 - 比如在以前使用 HTML中的标签。

I use TinyMCE to allow minimal formatting of text within my site. From the HTML that's produced, I'd like to convert it to plain text for e-mail. I've been using a class called html2text, but it's really lacking in UTF-8 support, among other things. I do, however, like that it maps certain HTML tags to plain text formatting — like putting underscores around text that previously had <i> tags in the HTML.

有没有人使用类似的方法将HTML转换为纯文本?如果是这样,你是否推荐任何可以使用的第三方课程?或者你最好如何解决这个问题?

Does anyone use a similar approach to converting HTML to plain text in PHP? And if so: Do you recommend any third-party classes that I can use? Or how do you best tackle this issue?

推荐答案

使用 html2text (示例 HTML 文字),根据 Eclipse公共许可证。它使用PHP的DOM方法从HTML加载,然后迭代生成的DOM以提取纯文本。用法:

Use html2text (example HTML to text), licensed under the Eclipse Public License. It uses PHP's DOM methods to load from HTML, and then iterates over the resulting DOM to extract plain text. Usage:

$text = convert_html_to_text($html);

虽然不完整,它是开源的,贡献是值得欢迎的。

Although incomplete, it is open source and contributions are welcome.

与其他转换脚本有关的问题:

Issues with other conversion scripts:

  • Since html2text (GPL) is not EPL-compatible.
  • lkessler's link (attribution) is incompatible with most open source licenses.

这篇关于将HTML转换为纯文本的PHP中的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆