voku / html2text
仅是 html2text 的分支 -> 将 HTML 转换为格式化的纯文本
5.0.4
2020-09-20 14:41 UTC
Requires
- php: >=7.0.0
- voku/portable-utf8: ~5.4
Requires (Dev)
- phpunit/phpunit: ~6.0 || ~7.0
- dev-master
- 5.0.4
- 5.0.3
- 5.0.2
- 5.0.1
- 5.0.0
- 4.0.0
- 3.4.12
- 3.4.11
- 3.4.10
- 3.4.9
- 3.4.8
- 3.4.7
- 3.4.6
- 3.4.5
- 3.4.4
- 3.4.3
- 3.4.2
- 3.4.1
- 3.4.0
- 3.3.0
- 3.2.2
- 3.2.1
- 3.2.0
- 3.1.20
- 3.1.19
- 3.1.18
- 3.1.17
- 3.1.16
- 3.1.15
- 3.1.14
- 3.1.13
- 3.1.12
- 3.1.11
- 3.1.10
- 3.1.9
- 3.1.8
- 3.1.7
- 3.1.6
- 3.1.5
- 3.1.4
- 3.1.3
- 3.1.2
- 3.1.1
- 3.1.0
- 3.0.1
- 3.0.0
- 2.0.1
- 2.0.0
- 1.0.1
- 1.0.0
- dev-dependabot/add-v2-config-file
- dev-whitesource/configure
- dev-analysis-q5090j
- dev-analysis-qg0Ekk
- dev-analysis-8nekBA
- dev-features/rc-formatting
This package is auto-updated.
Last update: 2024-09-04 02:33:03 UTC
README
📝 Html2Text
描述
将 HTML 转换为格式化的纯文本,例如用于文本邮件。
安装
推荐的安装方式是通过 Composer。
$ composer require voku/html2text
基本用法
$html = new \voku\Html2Text\Html2Text('Hello, "<b>world</b>"'); echo $html->getText(); // Hello, "WORLD"
扩展用法
每个元素(h1、li、div 等)都可以有如下选项
- 'case' => 转换大小写 (
Html2Text::OPTION_NONE, Html2Text::OPTION_UPPERCASE, Html2Text::OPTION_LOWERCASE, Html2Text::OPTION_UCFIRST, Html2Text::OPTION_TITLE
) - 'prepend' => 预置字符串
- 'append' => 添加字符串
例如
$html = '<h1>Should have "AAA" changed to BBB</h1><ul><li>• Custom bullet should be removed</li></ul><img alt="The Linux Tux" src="tux.png" />'; $expected = 'SHOULD HAVE "BBB" CHANGED TO BBB' . "\n\n" . '- Custom bullet should be removed |' . "\n\n" . '[IMAGE]: "The Linux Tux"'; $html2text = new Html2Text( $html, array( 'width' => 0, 'elements' => array( 'h1' => array( 'case' => Html2Text::OPTION_UPPERCASE, 'replace' => array('AAA', 'BBB')), 'li' => array( 'case' => Html2Text::OPTION_NONE, 'replace' => array('•', ''), 'prepend' => "- ", 'append' => " |", ), ), ) ); $html2text->setPrefixForImages('[IMAGE]: '); $html2text->setPrefixForLinks('[LINKS]: '); $html2text->getText(); // === $expected
在线演示
历史
这个库最初出现在 Jon Abernathy 的博客上 http://www.chuggnutt.com/html2text
一些项目开始使用这个库 - 其中包括 RoundCube 邮件。他们根据他们的网络邮件客户端对其进行了一些更新。
现在这是原始 Html2Text 的扩展分支。
支持
有关支持和支持请访问 Github | 问题 | PayPal | Patreon。
有关状态更新和发布公告,请访问 发布 | Twitter | Patreon。
如需专业支持,请联系 我。