PHPackages                             okneloper/placeholders - 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. okneloper/placeholders

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

okneloper/placeholders
======================

Batch replace placeholders in a (HTML) string.

v1.0.0(9y ago)017MITPHP

Since Nov 8Pushed 9y ago1 watchersCompare

[ Source](https://github.com/okneloper/placeholders)[ Packagist](https://packagist.org/packages/okneloper/placeholders)[ Docs](https://github.com/okneloper/placeholders)[ RSS](/packages/okneloper-placeholders/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (2)Versions (3)Used By (0)

Batch replace placeholders in a (HTML) string.

It gives you the full list of placeholders to resolve before replacing. This is handy when you have a lot of placeholders and you want to only fetch those that you need.

For instance, if your data is stored in a database or returned by a remote API, generally you want to fetch all data in one query/request.

\#Usage

```
$content = '

    :#:home.h1:#:
    :#:home.h2:#:

';

$content = $processor->process($content);

echo $content;

/*

    Welcome to the site!
    Slogan goes here

*/
```

See the full example for details of implementation.

Example
-------

[](#example)

```
/**
 * Define a placeholder translator by implementing Okneloper\Placeholders\Translator interface
 */
class ExamplePlaceholderTranslater implements Translator
{
    /**
     * @param PlaceholderCollection $placeholders
     * @return array
     */
    public function translate($placeholders)
    {
        $keys = $placeholders->keys();
        // fetch placeholders using keys from database
        // ...
        $data = [
            'home.h1' => 'Welcome to the site!',
            'home.h2' => 'Slogan goes here',
        ];

        $replacements = [];
        foreach ($placeholders as $placeholder) {
            $replacements[$placeholder->placeholder] = $data[$placeholder->key];
            // optionally apply filters found in $placeholder->filters
        }

        return $replacements;
    }
}

// Batch replace placeholders in a response
    /**
     * Handle the event.
     *
     * @param Request $request
     * @param Response $response
     */
    public function handle(Request $request, Response $response)
    {
        $content = $response->getContent();

        $processor = new Processor(new ExamplePlaceholderTranslater());

        $content = $processor->process($content);

        $response->setContent($content);
    }
```

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity64

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

Every ~0 days

Total

2

Last Release

3521d ago

Major Versions

v0.1.0 → v1.0.02016-11-08

### Community

Maintainers

![](https://www.gravatar.com/avatar/25fffe676901204d8fae9c25a681be94ff41b03b72ea1fee344683e30492cace?d=identicon)[okneloper](/maintainers/okneloper)

---

Top Contributors

[![pizzot](https://avatars.githubusercontent.com/u/15017593?v=4)](https://github.com/pizzot "pizzot (5 commits)")

---

Tags

placeholderreplaceplaceholders

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/okneloper-placeholders/health.svg)

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

###  Alternatives

[dflydev/placeholder-resolver

Given a data source representing key =&gt; value pairs, resolve placeholders like ${foo.bar} to the value associated with the 'foo.bar' key in the data source.

14214.6M3](/packages/dflydev-placeholder-resolver)[rosell-dk/dom-util-for-webp

Replace image URLs found in HTML

2417.7k5](/packages/rosell-dk-dom-util-for-webp)[filafly/filament-phosphor-icons

Phosphor icon pack for Filament Icons

1235.4k3](/packages/filafly-filament-phosphor-icons)[emanueleminotto/faker-placehold-it-provider

placehold.it provider for Faker

1423.5k1](/packages/emanueleminotto-faker-placehold-it-provider)

PHPackages © 2026

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