2017 © Pedro Peláez
 

library html2text

A PHP script to convert HTML into a plain text format

image

soundasleep/html2text

A PHP script to convert HTML into a plain text format

  • Wednesday, June 13, 2018
  • by soundasleep
  • Repository
  • 23 Watchers
  • 232 Stars
  • 529,539 Installations
  • HTML
  • 37 Dependents
  • 0 Suggesters
  • 81 Forks
  • 8 Open issues
  • 14 Versions
  • 13 % Grown

The README.md

example workflow Total Downloads

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:, (*1)

<html>
<title>Ignored Title</title>
<body>


Hello, World!

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

Even mismatched tags., (*2)

A div
Another div
A div
within a div
<a href="http://foo.com">A link</a> </body> </html>

Will be converted into:, (*3)

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., (*4)

Installing

You can use Composer to add the package to your project:, (*5)

{
  "require": {
    "soundasleep/html2text": "~1.1"
  }
}

And then use it quite simply:, (*6)

$text = \Soundasleep\Html2Text::convert($html);

You can also include the supplied html2text.php and use $text = convert_html_to_text($html); instead., (*7)

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.
char_set 'auto' Specify a specific character set. Pass multiple character sets (comma separated) to detect encoding, default is ASCII,UTF-8

Pass along options as a second argument to convert, for example:, (*8)

$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., (*9)

Troubleshooting

Class 'DOMDocument' not found

You need to install the PHP XML extension for your PHP version. e.g. apt-get install php7.4-xml, (*10)

License

html2text is licensed under MIT, making it suitable for both Eclipse and GPL projects., (*11)

Other versions

Also see html2text_ruby, a Ruby implementation., (*12)

The Versions

13/06 2018

dev-master

9999999-dev https://github.com/soundasleep/html2text

A PHP script to convert HTML into a plain text format

  Sources   Download

EPL-1.0

The Requires

  • php >=5.3.2
  • ext-dom *
  • ext-libxml *

 

The Development Requires

email php html text

20/04 2017

0.5.0

0.5.0.0 https://github.com/soundasleep/html2text

A PHP script to convert HTML into a plain text format

  Sources   Download

EPL-1.0

The Requires

  • php >=5.3.2
  • ext-dom *
  • ext-libxml *

 

The Development Requires

email php html text

09/06 2016

0.3.4

0.3.4.0 https://github.com/soundasleep/html2text

A PHP script to convert HTML into a plain text format

  Sources   Download

EPL-1.0

The Requires

  • php >=5.3.2
  • ext-dom *
  • ext-libxml *

 

The Development Requires

email php html text

08/06 2016

0.3.3

0.3.3.0 https://github.com/soundasleep/html2text

A PHP script to convert HTML into a plain text format

  Sources   Download

EPL-1.0

The Requires

  • php >=5.3.2
  • ext-dom *
  • ext-libxml *

 

The Development Requires

email php html text

08/06 2016

0.3.2

0.3.2.0 https://github.com/soundasleep/html2text

A PHP script to convert HTML into a plain text format

  Sources   Download

EPL-1.0

The Requires

  • php >=5.3.2
  • ext-dom *
  • ext-libxml *

 

The Development Requires

email php html text

25/02 2016

0.3.1

0.3.1.0 https://github.com/soundasleep/html2text

A PHP script to convert HTML into a plain text format

  Sources   Download

EPL-1.0

The Requires

  • php >=5.3.2
  • ext-dom *
  • ext-libxml *

 

The Development Requires

email php html text

18/01 2016

dev-non-breaking-space

dev-non-breaking-space https://github.com/soundasleep/html2text

A PHP script to convert HTML into a plain text format

  Sources   Download

EPL-1.0

The Requires

  • php >=5.3.2
  • ext-dom *
  • ext-libxml *

 

The Development Requires

email php html text

18/12 2015

0.3.0

0.3.0.0 https://github.com/soundasleep/html2text

A PHP script to convert HTML into a plain text format

  Sources   Download

EPL-1.0

The Requires

  • php >=5.3.2
  • ext-dom *
  • ext-libxml *

 

The Development Requires

email php html text

11/05 2015

0.2.3

0.2.3.0 https://github.com/soundasleep/html2text

A PHP script to convert HTML into a plain text format

  Sources   Download

EPL-1.0

The Requires

  • php >=5.3.2
  • ext-dom *
  • ext-libxml *

 

The Development Requires

email php html text

15/12 2014

0.2.2

0.2.2.0 https://github.com/soundasleep/html2text

A PHP script to convert HTML into a plain text format

  Sources   Download

EPL-1.0

The Requires

  • php >=5.3.2

 

The Development Requires

email php html text

10/12 2014

0.2.1

0.2.1.0 https://github.com/soundasleep/html2text

A PHP script to convert HTML into a plain text format

  Sources   Download

EPL-1.0

The Requires

  • php >=5.3.2

 

email php html text

08/12 2014

0.2.0

0.2.0.0 https://github.com/soundasleep/html2text

A PHP script to convert HTML into a plain text format

  Sources   Download

EPL-1.0

The Requires

  • php >=5.3.2

 

email php html text

30/05 2014

0.1.1

0.1.1.0 https://github.com/soundasleep/html2text

A PHP script to convert HTML into a plain text format

  Sources   Download

EPL-1.0

The Requires

  • php >=5.3.2

 

email php html text

16/05 2014

0.1.0

0.1.0.0 https://github.com/soundasleep/html2text

A PHP script to convert HTML into a plain text format

  Sources   Download

EPL-1.0

The Requires

  • php >=5.3.2

 

email php html text