PHPackages                             bit3/tag-replacer - 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. bit3/tag-replacer

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

bit3/tag-replacer
=================

Simply replace tags and add build-in logic into your string.

0276[1 issues](https://github.com/bit3archive/php-tag-replacer/issues)PHP

Since Dec 2Pushed 12y ago1 watchersCompare

[ Source](https://github.com/bit3archive/php-tag-replacer)[ Packagist](https://packagist.org/packages/bit3/tag-replacer)[ RSS](/packages/bit3-tag-replacer/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Tag Replacer
============

[](#tag-replacer)

This replacer replaces tags and add logic to strings.

Features
--------

[](#features)

### Tags

[](#tags)

Tags are special tags embraced in `{{` and `}}`. They have a name and may have arguments concatenated by `::` and parameters as query string.

#### Example

[](#example)

```
{{tag::argument1::argument2?param1=value1&param2=value2}}

```

#### Usage

[](#usage)

```
$replacer->registerTag('tag', function($name, $args, $params) {
	// $name   => 'tag'
	// $args   => array('argument1', 'argument2')
	// $params => array('param1' => 'value1, 'param2' => 'value2');
});
```

### Blocks

[](#blocks)

Blocks are special tags with a start and an end. They do something to the content they embrace.

**Hint:** You can register a block **and** a tag with the same name, but blocks are preferred before tags!

#### Example

[](#example-1)

```
{{myblock::argument1::argument2?param1=value1&param2=value2}}
Hello World
{{endmyblock}}

```

#### Usage

[](#usage-1)

```
$replacer->registerBlock('myblock', function($name, $args, $params, $body) {
	// $name   => 'myblock'
	// $args   => array('argument1', 'argument2')
	// $params => array('param1' => 'value1, 'param2' => 'value2');
	// $body   => "\nHello World\n"
});
```

### Recursive tags

[](#recursive-tags)

Recursive tags are tags inside of other tags or blocks.

#### Example

[](#example-2)

```
{{tag1::{{tag2}}}}

```

### Tokens

[](#tokens)

Tokens do not have own logic as tags have. They are simple key=&gt;value pairs. To use in the content, embrace the name with `##`.

#### Example

[](#example-3)

```
##mytoken##

```

#### Usage

[](#usage-2)

```
$replacer->setToken('mytoken', 'myvalue');
```

### Filters for Tags, Blocks and Tokens

[](#filters-for-tags-blocks-and-tokens)

Filters manipulate the value of a tag, block or token.

#### Examples

[](#examples)

```
{{tag|myfilter}}

```

```
{{block|myfilter}}
...
{{endblock}}

```

```
##token|myfilter##

```

#### Usage

[](#usage-3)

```
$replacer->registerFilter('myfilter', function($value) {
	// $value => the result of {{tag}}, {{block}}...{{endblock}} or ##token##
});
```

Handling unknown tokens
-----------------------

[](#handling-unknown-tokens)

By default, the Replacer will throw exceptions, but this behavior can be changed, there are three modes. The handling can be defined for tags and tokens or separately.

```
// trigger an error and leave empty
$replacer->setUnknownDefaultMode(TagReplacer::MODE_ERROR);

// trigger a warning and leave empty
$replacer->setUnknownTagMode(TagReplacer::MODE_WARNING);

// trigger a notice and leave empty
$replacer->setUnknownTokenMode(TagReplacer::MODE_NOTICE);
```

With `TagReplacer::MODE_EMPTY` an unknown tag/token will replaced with an empty value. With `TagReplacer::MODE_SKIP` an unknown tag/token will not replaced. Both can be used with or without `TagReplacer::MODE_ERROR`, `TagReplacer::MODE_WARNING` or `TagReplacer::MODE_NOTICE`.

```
// trigger an error, but leave the tag as it is
$replacer->setUnknownDefaultMode(TagReplacer::MODE_ERROR | TagReplacer::MODE_SKIP);

// leave the tag as it is, but do not trigger an error
$replacer->setUnknownDefaultMode(TagReplacer::MODE_SKIP);

// leave empty and do not trigger an error
$replacer->setUnknownDefaultMode(TagReplacer::MODE_EMPTY);
```

Caching
-------

[](#caching)

Insert Tags can be cached. Just use one of the doctrine cache implementations. The cache only affects insert tags, no blocks or tokens.

```
$replacer->setCache(new \Doctrine\Common\Cache\ArrayCache());
```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/4e61f74ea186c1e79e072b2974ccdeef39414730476d5a8adac501eb9449b2a3?d=identicon)[tril](/maintainers/tril)

---

Top Contributors

[![tristanlins](https://avatars.githubusercontent.com/u/343404?v=4)](https://github.com/tristanlins "tristanlins (12 commits)")

### Embed Badge

![Health badge](/badges/bit3-tag-replacer/health.svg)

```
[![Health](https://phpackages.com/badges/bit3-tag-replacer/health.svg)](https://phpackages.com/packages/bit3-tag-replacer)
```

PHPackages © 2026

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