PHPackages                             dneustadt/html-tag-replace - 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. [Search &amp; Filtering](/categories/search)
4. /
5. dneustadt/html-tag-replace

ActiveLibrary[Search &amp; Filtering](/categories/search)

dneustadt/html-tag-replace
==========================

Replace and enhance markup tags and/or attributes

1.0.0(8y ago)21141MITPHPCI failing

Since Dec 30Pushed 6y ago1 watchersCompare

[ Source](https://github.com/dneustadt/html-tag-replace)[ Packagist](https://packagist.org/packages/dneustadt/html-tag-replace)[ Docs](https://davidneustadt.de)[ RSS](/packages/dneustadt-html-tag-replace/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

HtmlTagReplace
==============

[](#htmltagreplace)

[![Scrutinizer](https://camo.githubusercontent.com/d66b9ed022664ea8e741563ebd798f0172b3c055a0138df8195d20cd5dea43e6/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f646e657573746164742f68746d6c2d7461672d7265706c6163652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/dneustadt/html-tag-replace/?branch=master)[![Travis CI](https://camo.githubusercontent.com/e770277a5774400554bac267ad17a0997e20a5ea772bb6d872dc9008c5a98374/68747470733a2f2f7472617669732d63692e6f72672f646e657573746164742f68746d6c2d7461672d7265706c6163652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/dneustadt/html-tag-replace)

a helper to replace and enhance html tags and their attributes.

Features
--------

[](#features)

- Append, prepend and switch tags.
- Add custom attributes to tags
- Switch, clone or remove attributes.

Usage
-----

[](#usage)

Create an Instance of `HtmlTagReplace` passing existing markup.

Use `replaceTag` method of said instance passing the following arguments:

- `search` Name of the tag to be replaced
- `replace` Name of the new tag
- `closingTag` (bool, default: false) defines whether searched tag has closing tag
- `argumentsReplace` (array) key-value pairs (`search => replace`) of attributes to be replaced. Multidimensional (`search => array`) to clone value into multiple arguments.
- `arguments` custom arguments injected
- `append` injected after targeted tag
- `prepend` injected before targeted tag

You can call the method `compress` to minify the markup.

Finally retrieve the altered markup calling `getMarkup`

Example
-------

[](#example)

```
$markup = '

    bar
    bar

';

$replacer = new HtmlTagReplace($markup);

echo $replacer->replaceTag(
        'img',
        'a',
        false,
        ['src' => 'href', 'alt' => false],
        'title="show image"',
        'show image'
    )->replaceTag(
        'div',
        'article',
        true,
        ['id' => 'class'],
        null,
        null,
        ''
    )->replaceTag(
        'em',
        'strong',
        true
    )->replaceTag(
        'input',
        'input',
        false,
        ['name' => ['name', 'id']]
    )->compress()->getMarkup();
```

will result in (not minified for readability):

```
show image
show image
bar
bar

```

Todos
=====

[](#todos)

- add more filter options for targeting tags
- optimize method for filtering and replacing arguments
- content manipulation
- synchronized replacement

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity63

Established project with proven stability

 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

3106d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/69c1745bd6023c706f651e9bdb38515fc7678caf52b9580126141381168669cd?d=identicon)[dneustadt](/maintainers/dneustadt)

---

Top Contributors

[![dneustadt](https://avatars.githubusercontent.com/u/9033214?v=4)](https://github.com/dneustadt "dneustadt (1 commits)")

---

Tags

attributesdomhtmlmarkupreplacesearchtagsdomattributestagsmarkupreplace

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/dneustadt-html-tag-replace/health.svg)

```
[![Health](https://phpackages.com/badges/dneustadt-html-tag-replace/health.svg)](https://phpackages.com/packages/dneustadt-html-tag-replace)
```

###  Alternatives

[mjohnson/decoda

A lightweight lexical string parser for BBCode styled markup.

1921.3M14](/packages/mjohnson-decoda)[digital-creative/nova-pill-filter

A Laravel Nova filter that renders into clickable pills.

1661.9k1](/packages/digital-creative-nova-pill-filter)[stolz/laravel-html-tidy

HTML Tidy middleware for Laravel

268.7k](/packages/stolz-laravel-html-tidy)[stevegrunwell/phpunit-markup-assertions

Assertions for PHPUnit to verify the presence or state of elements within markup

16156.6k5](/packages/stevegrunwell-phpunit-markup-assertions)[mediamonks/crawler

Crawl your own website with various clients for SEO and indexing purposes.

211.1k1](/packages/mediamonks-crawler)

PHPackages © 2026

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