PHPackages                             stevebauman/hypertext - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. stevebauman/hypertext

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

stevebauman/hypertext
=====================

The best HTML to text transformer

v1.1.2(1y ago)171472.6k↓21.5%6[1 issues](https://github.com/stevebauman/hypertext/issues)2MITPHPCI passing

Since Oct 22Pushed 10mo ago2 watchersCompare

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

READMEChangelog (5)Dependencies (3)Versions (7)Used By (2)

Hypertext
=========

[](#hypertext)

A PHP HTML to pure text transformer that beautifully handles various and malformed HTML.

[![](https://camo.githubusercontent.com/33748f7e9d485ac2b3ea7276263bd99a820d8078a6bb4939203c3a06914cf661/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f73746576656261756d616e2f6879706572746578742f72756e2d74657374732e796d6c3f6272616e63683d6d6173746572267374796c653d666c61742d737175617265)](https://github.com/stevebauman/hypertext/actions)[![](https://camo.githubusercontent.com/eab70ac614b91744b6e8a2a777b16f35d9363caf8c84a6d1a4d8f3b29bcceeaa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73746576656261756d616e2f6879706572746578742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/stevebauman/hypertext)[![](https://camo.githubusercontent.com/8df26e4dce5b92e9a19a7e7cc1ce4c0f37d627373a6ac5690502c81a77ad01f4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73746576656261756d616e2f6879706572746578742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/stevebauman/hypertext)[![](https://camo.githubusercontent.com/d2a390bb9c8a26fb2b1f108af88cf97d577b2e12ed1f3e379d2e1bc40973b62c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f73746576656261756d616e2f6879706572746578742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/stevebauman/hypertext)

---

Hypertext is excellent at pulling text content out of any HTML based document and automatically:

- Removes CSS
- Removes scripts
- Removes headers
- Removes non-HTML based content
- Preserves spacing
- Preserves links (optional)
- Preserves new lines (optional)

It is directed at using the output in LLM related tasks, such as prompts and embeddings.

Installation
------------

[](#installation)

```
composer require stevebauman/hypertext
```

Usage
-----

[](#usage)

```
use Stevebauman\Hypertext\Transformer;

$transformer = new Transformer();

// (Optional) Filter out specific elements by their XPath.
$transformer->filter("//*[@id='some-element']");

// (Optional) Retain new line characters.
$transformer->keepNewLines();

// (Optional) Retain anchor tags and their href attribute.
$transformer->keepLinks();

$text = $transformer->toText($html);
```

Example
-------

[](#example)

> For larger examples, please view the [tests/Fixtures](https://github.com/stevebauman/hypertext/tree/master/tests/Fixtures) directory.

**Input**:

```
>

    My Blog

    Welcome to My Blog
    This is a paragraph of text on my webpage.
    Click here to view my posts.

```

**Output (Pure Text)**:

```
echo (new Transformer)->toText($html);
```

```
Welcome to My Blog This is a paragraph of text on my webpage. Click here to view my posts.

```

**Output (Keep New Lines)**:

```
echo (new Transformer)->keepNewLines()->toText($html);
```

```
Welcome to My Blog
This is a paragraph of text on my webpage.
Click here to view my posts.

```

**Output (Keep Links)**:

```
echo (new Transformer)->keepLinks()->toText($html);
```

```
Welcome to My Blog This is a paragraph of text on my webpage. Click Here to view my posts.

```

**Output (Keep Both)**:

```
echo (new Transformer)
    ->keepLinks()
    ->keepNewLines()
    ->toText($html);
```

```
Welcome to My Blog
This is a paragraph of text on my webpage.
Click Here to view my posts.

```

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance46

Moderate activity, may be stable

Popularity53

Moderate usage in the ecosystem

Community18

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 95.9% 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.

###  Release Activity

Cadence

Every ~89 days

Total

5

Last Release

583d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c6dd082636ff8a08df8dfdcd622ea242374d1d76dd33bceec5a6cd3ae26dc24f?d=identicon)[stevebauman](/maintainers/stevebauman)

---

Top Contributors

[![stevebauman](https://avatars.githubusercontent.com/u/6421846?v=4)](https://github.com/stevebauman "stevebauman (47 commits)")[![mrk-j](https://avatars.githubusercontent.com/u/1250622?v=4)](https://github.com/mrk-j "mrk-j (1 commits)")[![peterfox](https://avatars.githubusercontent.com/u/1716506?v=4)](https://github.com/peterfox "peterfox (1 commits)")

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/stevebauman-hypertext/health.svg)

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

###  Alternatives

[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k20](/packages/civicrm-civicrm-core)[caxy/php-htmldiff

A library for comparing two HTML files/snippets and highlighting the differences using simple HTML.

21520.9M15](/packages/caxy-php-htmldiff)[getdkan/dkan

DKAN Open Data Catalog

385135.4k2](/packages/getdkan-dkan)[verbb/formie

The most user-friendly forms plugin for Craft.

101372.9k40](/packages/verbb-formie)[trsteel/ckeditor-bundle

Symfony bundle for easy integration of the CKEditor WYSIWYG

99630.9k9](/packages/trsteel-ckeditor-bundle)[fisharebest/webtrees

webtrees online genealogy

73710.5k13](/packages/fisharebest-webtrees)

PHPackages © 2026

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