Description
html2text is a very simple script that uses PHP's DOM methods to load from HTML, and then iterates over the resulting DOM to correctly output plain text. For example:
html2text alternatives and similar libraries
Based on the "Miscellaneous" category.
Alternatively, view html2text alternatives based on common mentions on social networks and blogs.
-
Country List
:globe_with_meridians: List of all countries with names and ISO 3166-1 codes in all languages and data formats. -
Hprose-PHP
Hprose is a cross-language RPC. This project is Hprose 3.0 for PHP -
dotenv-linter
⚡️Lightning-fast linter for .env files. Written in Rust 🦀 -
SuperClosure
Serialize closures. Not maintained. Consider using opis/closure. -
Pagerfanta
Pagination library for PHP applications with support for several data providers -
Essence
Extracts information about web pages, like youtube videos, twitter statuses or blog articles. -
sabre/vobject
:date: The VObject library for PHP allows you to easily parse and manipulate iCalendar and vCard objects -
Token Bucket
Implementation of the Token Bucket algorithm in PHP. -
Prooph Service Bus
PHP Lightweight Message Bus supporting CQRS. -
Lodash-PHP
Easy to use utility functions for everyday PHP projects. This is a port of the Lodash JS library to PHP -
noCAPTCHA
:passport_control: Helper for Google's new noCAPTCHA (reCAPTCHA v2 & v3) -
Embera
A Oembed consumer library, that gives you information about urls. It helps you replace urls to youtube or vimeo for example, with their html embed code. It has advanced features like offline support, responsive embeds and caching support. -
ClassPreloader
Optimizes class loading performance by generating a single PHP file containing all of the autoloaded files. -
Metrics
Simple library that abstracts different metrics collectors. I find this necessary to have a consistent and simple metrics (functional) API that doesn't cause vendor lock-in. -
Slimdump
A tool for creating configurable dumps of large MySQL-databases. -
git-profile
Utility that helps you switch git configurations with ease. -
Cake Utility
[READ-ONLY] CakePHP Utility classes such as Inflector, Text, Hash, Security and Xml. This repo is a split of the main code that can be found in https://github.com/cakephp/cakephp -
RedisSessionHandler
An alternative Redis session handler for PHP featuring per-session locking and session fixation protection -
html-object
A set of classes to create and manipulate HTML objects abstractions -
Sslurp
Sslurp is a simple library which aims to make properly dealing with SSL in PHP suck less. -
Procrastinator
Execute time consuming tasks as late as possible in a request -
Yell
PHP package to make your objects strict and throw exception when you try to access or set some undefined property in your objects.
Clean code begins in your IDE with SonarLint
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of html2text or a related project?
README
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:
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)
See the original blog post or the related StackOverflow answer.
Installing
You 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 html2text.php
and use $text = convert_html_to_text($html);
instead.
Options
Option | Default | Description |
---|---|---|
ignore_errors | false |
Set to true to ignore any XML parsing errors. |
drop_links | false |
Set to true to not render links as [http://foo.com](My Link) , but rather just My Link . |
Pass along options as a second argument to convert
, for example:
$options = array(
'ignore_errors' => true,
// other options go here
);
$text = \Soundasleep\Html2Text::convert($html, $options);
Tests
Some very basic tests are provided in the tests/
directory. Run them with composer install && vendor/bin/phpunit
.
Troubleshooting
Class 'DOMDocument' not found
You need to install the PHP XML extension for your PHP version. e.g. apt-get install php7.1-xml
License
html2text
is [licensed under MIT](LICENSE.md), making it suitable for both Eclipse and GPL projects.
Other versions
Also see html2text_ruby, a Ruby implementation.
*Note that all licence references and agreements mentioned in the html2text README section above
are relevant to that project's source code only.