PHPackages                             vanderlee/enricher - 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. [Mail &amp; Notifications](/categories/mail)
4. /
5. vanderlee/enricher

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

vanderlee/enricher
==================

Backfill (add only if missing), overwrite and remove classes, style rules and attributes in HTML by using selectors.

1.0.2(9y ago)015MITPHPPHP &gt;=5.3.0

Since Oct 24Pushed 9y ago1 watchersCompare

[ Source](https://github.com/vanderlee/Enricher)[ Packagist](https://packagist.org/packages/vanderlee/enricher)[ Docs](https://github.com/vanderlee/Enricher)[ RSS](/packages/vanderlee-enricher/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependenciesVersions (2)Used By (0)

Enricher
========

[](#enricher)

Version 1.0.2

[![Build Status](https://camo.githubusercontent.com/075d3fed38a2d6c59e54abd0e437ded27fb1afffefb11037cd3eaec281085197/68747470733a2f2f7472617669732d63692e6f72672f76616e6465726c65652f456e7269636865722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/vanderlee/Enricher)

Copyright © 2016 Martijn van der Lee. MIT Open Source license applies.

Introduction
------------

[](#introduction)

Backfill (add only if missing), overwrite and remove classes, style rules and attributes in HTML by using selectors.

Basic but fast HTML attribute and style modifier for PHP. Similar to Emogrifier with only basic selectors, but added attribute support. It's primary purpose is to change HTML for use in emails, but it is not in any way limited to this particular use case.

Features
--------

[](#features)

- Change styles, attributes and classes.
- Add (if missing), overwrite and remove in one run.
- Select based on tag names, class names, id's and/or presence of attributes.
- Multiple selectors in one run.
- Fast.

Comparison to Emogrifier
------------------------

[](#comparison-to-emogrifier)

Enricher's functionality and purpose has significant overlap with Emogrifier (), but is different in a few key ways.

- Both have full unittests.
- Both support element selectors. i.e. `a`
- Both support ID selectors. i.e. `#logo`.
- Both support class selectors. i.e. `table.mobile`.
- Both support attribute selectors. i.e. `a[name]`.
- Both support composite selectors. i.e. `a[name].mobile`.
- (+) Enricher is ***much*** faster than Emogrifier. Upto several orders of magnitude.
- (+) Enricher supports adding and removing attributes.
- (+) Enricher supports adding and removing classes.
- (+) Enricher supports adding, overwriting and removing in one go.
- (-) Emogrifier supports "path" selectors. i.e. `#list a.item`.
- (-) Emogrifier supports pseudoselectors. i.e. `:nth-child`.
- (-) Emogrifier supports attribute value selectors. i.e. `[name=anchor]`.
- (/) Emogrifier requires valid HTML, which may or may not be an issue, depending on usage scenario.

In general; if you need complex selectors such as paths, use Emogrifier. If you need class or attribute changing or complex CSS rewriting, use Enricher. In other cases Enricher will do the same job, but faster.

Future plans
------------

[](#future-plans)

- Support `*` as an "all-elements" wildcard.
- Support more complex selectors.

Documentation
=============

[](#documentation)

Here you will find basic instructions to get you started. You can find complete PHPDoc in the /doc directory.

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

[](#installation)

Get the latest version here:

Enricher requires atleast PHP 5.3 or HHVM.

Either include the autoloader (for forwards compatibility) or `include` the `Enricher.php` file directly or through your own autoloader.

Constructor
-----------

[](#constructor)

The constructor does nothing.

Methods
-------

[](#methods)

### `reset()`

[](#reset)

Clear out all selectors, attribute, style and class settings.

### `addSelector($selector)`/`addSelectors($selectors)`

[](#addselectorselectoraddselectorsselectors)

Add a selectors to specify which elements may be selected.

- Select elements by specifying the tag. i.e. `div`.
- Select by class by specifying the class. i.e. `div.blue`.
- Select by id by specifying the id. i.e. `div#body`.
- Select by attribute by specifying the attribute. i.e. `a[href]`.
- Combine these to form selectors. i.e. `a[href][target].blue`.
- You may specify multiple selectors by separating them using a comma (,).

### `addAttribute($name, $value)`/`addAttributes($attributes)`

[](#addattributename-valueaddattributesattributes)

### `overwriteAttribute($name, $value)`/`overwriteAttributes($attributes)`

[](#overwriteattributename-valueoverwriteattributesattributes)

### `removeAttribute($name)`/`removeAttributes($names)`

[](#removeattributenameremoveattributesnames)

Add (if missing), overwrite or remove attributes.

### `addStyle($name, $value)`/`addStyles($styles)`

[](#addstylename-valueaddstylesstyles)

### `overwriteStyle($name, $value)`/`overwriteStyles($styles)`

[](#overwritestylename-valueoverwritestylesstyles)

### `removeStyle($name)`/`removeStyles($names)`

[](#removestylenameremovestylesnames)

Add (if missing), overwrite or remove style rules.

### `addClass($name)`/`addClasses($names)`

[](#addclassnameaddclassesnames)

### `removeClass($name)`/`removeClasses($names)`

[](#removeclassnameremoveclassesnames)

Add or remove classes.

### `enrich($html)`

[](#enrichhtml)

Enrich the HTML according the the settings. If settings are missing, an empty HTML will be returned.

Example
-------

[](#example)

```
require_once 'Enricher.php';

$enricher = new Enricher();

$enricher->addSelector('a[href]');

$enricher->addStyle('color', 'black');
$enricher->addAttribute('title', 'I'm a hyperlink');

echo $enricher->enrich($html);
```

###  Health Score

25

—

LowBetter than 36% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

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

Unknown

Total

1

Last Release

3535d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/59428f021d3985e299ebd676bbe50fa592430f8dd1d57af38df8833b19079ee8?d=identicon)[vanderlee](/maintainers/vanderlee)

---

Top Contributors

[![vanderlee](https://avatars.githubusercontent.com/u/649240?v=4)](https://github.com/vanderlee "vanderlee (30 commits)")

---

Tags

emailhtmlselectoremogrifierenricher

### Embed Badge

![Health badge](/badges/vanderlee-enricher/health.svg)

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

###  Alternatives

[soundasleep/html2text

A PHP script to convert HTML into a plain text format

48020.6M85](/packages/soundasleep-html2text)[snowfire/beautymail

Send beautiful html emails with Laravel

1.3k746.6k2](/packages/snowfire-beautymail)[voku/html2text

Only a Fork of -&gt; html2text: Converts HTML to formatted plain text

38340.6k2](/packages/voku-html2text)[markguinn/silverstripe-email-helpers

Silverstripe extension containing SMTP mailer class and some other classes for HTML emails

3145.6k1](/packages/markguinn-silverstripe-email-helpers)[osiemsiedem/laravel-autolink

A Laravel package for converting URLs in a given string of text into clickable links.

13135.2k](/packages/osiemsiedem-laravel-autolink)

PHPackages © 2026

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