apt142/htmltotext

一个用于将HTML转换为纯文本格式的PHP类

0.1.1 2014-05-30 00:48 UTC

This package is not auto-updated.

Last update: 2024-09-24 06:46:45 UTC


README

#HtmlToText 构建状态 最新稳定版本 总下载量 许可证

html2text是一个非常简单的脚本,它使用PHP的DOM方法从HTML中加载,然后遍历生成的DOM以输出纯文本。

示例

<html>
<title>Ignored Title</title>
<body>
  <h1>Hello, World!</h1>

  <p>This is some e-mail content.
  Even though it has whitespace and newlines, the e-mail converter
  will handle it correctly.

  <p>Even mismatched tags.</p>

  <div>A div</div>
  <div>Another div</div>
  <div>A div<div>within a div</div></div>

  <a href="http://foo.com">A link</a>

</body>
</html>

将被转换为

Hello, World!

This is some e-mail content. Even though it has whitespace and newlines, the e-mail converter will handle it correctly.

Even mismatched tags.
A div
Another div
A div
within a div
[A link](http://foo.com)

这是对以下项目的分支:(https://github.com/soundasleep/html2text)

安装

您可以使用Composer将此添加到您的项目中

{
  "require": {
    "apt142/htmltotext": "dev-master"
  }
}

然后非常简单地使用它

$converter = new \HtmlToText\HtmlToText($html);
$text = $converter->convert();

// Or

$converter = new \HtmlToText\HtmlToText();
$convertor->set($html);
$text = $converter->convert();