在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:soundasleep/html2text开源软件地址:https://github.com/soundasleep/html2text开源编程语言:HTML 98.9%开源软件介绍:html2text is a very simple script that uses DOM methods to convert HTML into a format similar to what would be rendered by a browser - perfect for places where you need a quick text representation. For example: <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> Will be converted into:
See the original blog post or the related StackOverflow answer. InstallingYou can use Composer to add the package to your project: {
"require": {
"soundasleep/html2text": "~1.1"
}
} And then use it quite simply: $text = \Soundasleep\Html2Text::convert($html); You can also include the supplied Options
Pass along options as a second argument to $options = array(
'ignore_errors' => true,
// other options go here
);
$text = \Soundasleep\Html2Text::convert($html, $options); TestsSome very basic tests are provided in the TroubleshootingClass 'DOMDocument' not foundYou need to install the PHP XML extension for your PHP version. e.g. License
Other versionsAlso see html2text_ruby, a Ruby implementation. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论