PHPackages                             nabeghe/text-binder - 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. nabeghe/text-binder

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

nabeghe/text-binder
===================

A lightweight PHP text binding library with placeholder replacement and chained function support.

00PHP

Since Jan 29Pushed 3mo agoCompare

[ Source](https://github.com/nabeghe/text-binder-php)[ Packagist](https://packagist.org/packages/nabeghe/text-binder)[ RSS](/packages/nabeghe-text-binder/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

TextBinder for PHP ≥ 7.4
========================

[](#textbinder-for-php--74)

> A lightweight and flexible text binding engine with support for chained placeholder functions.

TextBinder is a small PHP library for binding variables into text using placeholders, with the ability to apply chained functions to transform values on the fly. It is designed to be simple, extensible, and dependency-free.

---

Features
--------

[](#features)

- Simple placeholder replacement using `{variable}` syntax
- Chained function support: `{variable.func1.func2}` (multiple functions in sequence)
- Built-in helper functions (`exists`, `ok`)
- Support for custom user-defined functions
- Automatic normalization of function outputs
- Zero dependencies (except `ext-json`)
- Compatible with PHP 7.4+

---

🫡 Usage
-------

[](#-usage)

### 🚀 Installation

[](#-installation)

You can install the package via composer:

```
composer require nabeghe/text-binder
```

Or manually include the TextBinder.php if you want to keep it old school.

### Basic Example

[](#basic-example)

```
use Nabeghe\TextBinder\TextBinder;

$binder = new TextBinder();

$text = 'Hello {name}!';
echo $binder->render($text, [
    'name' => 'Elsa'
]);
```

**Output:**`Hello Elsa!`

### Chained Functions (Multiple Functions in Sequence)

[](#chained-functions-multiple-functions-in-sequence)

TextBinder allows applying multiple functions to a single placeholder using dot notation:

```
$binder->addFunc('upper', fn($v) => strtoupper($v));
$binder->addFunc('surround', fn($v) => ">>$v
