PHPackages                             kkirillov25/html2text - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. kkirillov25/html2text

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

kkirillov25/html2text
=====================

A PHP script to convert HTML into a plain text format (fork with Outlook &amp;nbsp; fix)

014↓100%HTML

Since Mar 16Pushed 1mo agoCompare

[ Source](https://github.com/kkirillov25/simple-html2text)[ Packagist](https://packagist.org/packages/kkirillov25/html2text)[ RSS](/packages/kkirillov25-html2text/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

[![example workflow](https://github.com/soundasleep/html2text/actions/workflows/test.yml/badge.svg)](https://github.com/soundasleep/html2text/actions/workflows/test.yml/badge.svg) [![Total Downloads](https://camo.githubusercontent.com/9e4a7d4a0a88d868d5ec5b11b5a29d2b5bb620adc808bdcfb242347954b886d2/68747470733a2f2f706f7365722e707567782e6f72672f736f756e6461736c6565702f68746d6c32746578742f646f776e6c6f6164732e706e67)](https://packagist.org/packages/soundasleep/html2text)
========================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#-)

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:

```

Ignored Title

  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 divwithin a div

  A link

```

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](http://journals.jevon.org/users/jevon-phd/entry/19818) or the related [StackOverflow answer](http://stackoverflow.com/a/2564472/39531).

Installing
----------

[](#installing)

You can use [Composer](http://getcomposer.org/) to add the [package](https://packagist.org/packages/soundasleep/html2text) 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

[](#options)

OptionDefaultDescription**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-8Pass 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
-----

[](#tests)

Some very basic tests are provided in the `tests/` directory. Run them with `composer install && vendor/bin/phpunit`.

Troubleshooting
---------------

[](#troubleshooting)

### Class 'DOMDocument' not found

[](#class-domdocument-not-found)

You need to [install the PHP XML extension](https://github.com/soundasleep/html2text/issues/55) for your PHP version. e.g. `apt-get install php7.4-xml`

License
-------

[](#license)

`html2text` is [licensed under MIT](LICENSE.md), making it suitable for both Eclipse and GPL projects.

Other versions
--------------

[](#other-versions)

Also see [html2text\_ruby](https://github.com/soundasleep/html2text_ruby), a Ruby implementation.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance62

Regular maintenance activity

Popularity8

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 Bus Factor1

Top contributor holds 69.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/953d70f740dc49a14f6c8f9b00468c5661787aad77d9ceccd559158be9da07d9?d=identicon)[kkirillov25](/maintainers/kkirillov25)

---

Top Contributors

[![soundasleep](https://avatars.githubusercontent.com/u/3889656?v=4)](https://github.com/soundasleep "soundasleep (85 commits)")[![phpfui](https://avatars.githubusercontent.com/u/7434059?v=4)](https://github.com/phpfui "phpfui (14 commits)")[![edgrosvenor](https://avatars.githubusercontent.com/u/1053395?v=4)](https://github.com/edgrosvenor "edgrosvenor (7 commits)")[![vanhoavn](https://avatars.githubusercontent.com/u/3288188?v=4)](https://github.com/vanhoavn "vanhoavn (2 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (2 commits)")[![manzoorwanijk](https://avatars.githubusercontent.com/u/18226415?v=4)](https://github.com/manzoorwanijk "manzoorwanijk (1 commits)")[![maskas](https://avatars.githubusercontent.com/u/1159983?v=4)](https://github.com/maskas "maskas (1 commits)")[![pethersonmorenosqg](https://avatars.githubusercontent.com/u/9138772?v=4)](https://github.com/pethersonmorenosqg "pethersonmorenosqg (1 commits)")[![jaylinski](https://avatars.githubusercontent.com/u/1668766?v=4)](https://github.com/jaylinski "jaylinski (1 commits)")[![SDKiller](https://avatars.githubusercontent.com/u/2150916?v=4)](https://github.com/SDKiller "SDKiller (1 commits)")[![guillaume-ro-fr](https://avatars.githubusercontent.com/u/1820051?v=4)](https://github.com/guillaume-ro-fr "guillaume-ro-fr (1 commits)")[![Stadly](https://avatars.githubusercontent.com/u/7263579?v=4)](https://github.com/Stadly "Stadly (1 commits)")[![thetaylor82](https://avatars.githubusercontent.com/u/2462662?v=4)](https://github.com/thetaylor82 "thetaylor82 (1 commits)")[![timothyasp](https://avatars.githubusercontent.com/u/707699?v=4)](https://github.com/timothyasp "timothyasp (1 commits)")[![tommygnr](https://avatars.githubusercontent.com/u/929392?v=4)](https://github.com/tommygnr "tommygnr (1 commits)")[![ulrichsg](https://avatars.githubusercontent.com/u/197901?v=4)](https://github.com/ulrichsg "ulrichsg (1 commits)")[![cyrosy](https://avatars.githubusercontent.com/u/2836107?v=4)](https://github.com/cyrosy "cyrosy (1 commits)")

### Embed Badge

![Health badge](/badges/kkirillov25-html2text/health.svg)

```
[![Health](https://phpackages.com/badges/kkirillov25-html2text/health.svg)](https://phpackages.com/packages/kkirillov25-html2text)
```

###  Alternatives

[mtdowling/jmespath.php

Declaratively specify how to extract elements from a JSON document

2.0k472.8M135](/packages/mtdowling-jmespathphp)[opis/closure

A library that can be used to serialize closures (anonymous functions) and arbitrary data.

2.6k230.0M283](/packages/opis-closure)[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M226](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M63](/packages/sabberworm-php-css-parser)[michelf/php-markdown

PHP Markdown

3.5k52.4M344](/packages/michelf-php-markdown)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
