PHPackages                             angelopereyra/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. angelopereyra/replace

ActiveLibrary

angelopereyra/replace
=====================

Replace substring using custom identifiers

v1.1.0(7y ago)214MITPHP

Since Feb 8Pushed 7y ago1 watchersCompare

[ Source](https://github.com/angeloPereyra/replace)[ Packagist](https://packagist.org/packages/angelopereyra/replace)[ RSS](/packages/angelopereyra-replace/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (3)Dependencies (2)Versions (6)Used By (0)

[![Build Status](https://camo.githubusercontent.com/ca6ae8381ce10f190838188a7b5a07613ff0553d6ef22bf6ad2fea5c31b18f2a/68747470733a2f2f7472617669732d63692e636f6d2f616e67656c6f506572657972612f7265706c6163652e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/angeloPereyra/replace)

Installation
============

[](#installation)

```
> composer require angelopereyra/replace
```

Usage
=====

[](#usage)

```
use Replace\Replaceable;

...

$url = new Replaceable('https://mysite.{domain}.com');
```

From the above example, we can set the value for `{domain}` substring in two ways:

```
$url->addLookup('domain', 'local');

// dumping a dictionary
$url->setLookup([
    'domain' => 'local'
]);
```

Then cast the object to string to get the result

```
echo (string)$url; // prints "https://mysite.local.com"
```

Modify the token format
-----------------------

[](#modify-the-token-format)

Pass a string as a second argument to the constructor to customize what your token would look like:

```
$url = new Replaceable('https://mysite.$$domain.com', '$$++key++');
// ++key++ is the 🔑
```

In some cases you might just need to pass a callable:

```
$url = new Replaceable('https://mysite.UwU domain UwU.com', function($key) {
    return 'UwU ' . $key . ' UwU';
});
```

A static helper is also exposed for convenience

```
$lookup = [
    'type'   => 'Bearer',
    'token'  => 'xoxb-83029aurioDnd'
];

Replaceable::parse('Authorization: @type @token', $lookup, '@++key++')
// prints "Authorization: Bearer xoxb-83029aurioDnd"
```

Identify tokens
---------------

[](#identify-tokens)

Suppose you have the subject string below:

```
Hello, {name}. You look {adjective} today.

```

Replaceable can identify the tokens according to the given token format. In this case, we will be using the default format which is `{++key++}`.

We can identify the tokens using the following usage:

```
$subject = file_get_contents('...');

$sentence = new Replaceable($subject);

$sentence->identifyTokens(false);
// returns ['name', 'adjective']
```

To identify tokens with respect to word boundary, set the 1st parameter to true:

```
$sentence->identifyTokens(true);
// returns ['adjective']
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

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 ~15 days

Total

4

Last Release

2607d ago

Major Versions

v0.1.0 → v1.0.02019-02-16

### Community

Maintainers

![](https://www.gravatar.com/avatar/72d61b8b56423aa350c5273ba268a28fb1135d1504802b82051ecd6c142eaa4b?d=identicon)[angelopereyra](/maintainers/angelopereyra)

---

Top Contributors

[![angeloPereyra](https://avatars.githubusercontent.com/u/20628472?v=4)](https://github.com/angeloPereyra "angeloPereyra (24 commits)")

---

Tags

phpregexsearch-and-replacestringtoken

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/angelopereyra-replace/health.svg)

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

PHPackages © 2026

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