PHPackages                             yuanqing/interpolate - 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. yuanqing/interpolate

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

yuanqing/interpolate
====================

Simple string interpolation in PHP.

v1.2.1(11y ago)55.8k1MITPHPPHP &gt;=5.3

Since Jul 10Pushed 11y agoCompare

[ Source](https://github.com/yuanqing/interpolate)[ Packagist](https://packagist.org/packages/yuanqing/interpolate)[ Docs](https://github.com/yuanqing/interpolate)[ RSS](/packages/yuanqing-interpolate/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)DependenciesVersions (7)Used By (0)

Interpolate.php [![Packagist Version](https://camo.githubusercontent.com/fb7579de294c0cc3a56b3fcd743628410eee703b59f3ba289e787b22fe76ed5a/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7975616e71696e672f696e746572706f6c6174652e7376673f7374796c653d666c6174)](https://packagist.org/packages/yuanqing/interpolate) [![Build Status](https://camo.githubusercontent.com/458edaa482cda34b0cbc92e90cbe3442513fb6b5877cd17a4b965520f821782e/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7975616e71696e672f696e746572706f6c6174652e7376673f7374796c653d666c6174)](https://travis-ci.org/yuanqing/interpolate) [![Coverage Status](https://camo.githubusercontent.com/4d0ba53808aee702fed4064d389dc80a01aa8fea985442e4a48943f2993f6ebf/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f7975616e71696e672f696e746572706f6c6174652e7376673f7374796c653d666c6174)](https://coveralls.io/r/yuanqing/interpolate)
=================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#interpolatephp---)

A small PHP package for interpolating values from an array into a template string.

Think of it as a lightweight alternative to [Mustache](https://github.com/bobthecow/mustache.php):

```
use yuanqing\Interpolate\Interpolate;

$i = new Interpolate;
$tmpl = '{{ foo.bar }}, {{ foo.baz }}!';
$data = array(
  'foo' => array(
    'bar' => 'Hello',
    'baz' => 'World'
  )
);
$i->render($tmpl, $data); #=> 'Hello, World!'
```

Usage
-----

[](#usage)

1. Tags are enclosed in double braces.
2. Straight-up substitution; there are no conditional blocks, sections and so forth.
3. Tags can reference nested values in the multidimensional array (as in the example above).
4. A value to be interpolated can be a [scalar](http://php.net/manual/en/function.is-scalar.php), an object that implements `__toString()`, or a callback that returns a string:

    ```
    $i = new Interpolate;
    $tmpl = '{{ baz }}';
    $data = array(
      'foo' => 'Hello',
      'bar' => 'World',
      'baz' => function($data) {
        return sprintf('%s, %s!', $data['foo'], $data['bar']);
      }
    );
    $i->render($tmpl, $data); #=> 'Hello, World!'
    ```

    Note that the first argument of the callback is the `$data` array.
5. If a value for a tag is not found, the tag will be replaced with an empty string.

The two examples in this README may be found in [the examples.php file](https://github.com/yuanqing/interpolate/blob/master/examples.php).

Requirements
------------

[](#requirements)

Interpolate.php requires at least **PHP 5.3**, or **HHVM**.

Installation
------------

[](#installation)

### Install with Composer

[](#install-with-composer)

1. Install [Composer](http://getcomposer.org/).
2. Install [the Interpolate.php Composer package](https://packagist.org/packages/yuanqing/interpolate):

    ```
    $ composer require yuanqing/interpolate ~1.2
    ```
3. In your PHP, require the Composer autoloader:

    ```
    require_once __DIR__ . '/vendor/autoload.php';
    ```

### Install manually

[](#install-manually)

1. Clone this repository:

    ```
    $ git clone https://github.com/yuanqing/interpolate
    ```

    Or just [grab the zip](https://github.com/yuanqing/interpolate/archive/master.zip).
2. In your PHP, require [Interpolate.php](https://github.com/yuanqing/interpolate/blob/master/src/Interpolate.php):

    ```
    require_once __DIR__ . '/src/Interpolate.php';
    ```

Testing
-------

[](#testing)

You need [PHPUnit](http://phpunit.de/) to run the tests:

```
$ git clone https://github.com/yuanqing/interpolate
$ cd interpolate
$ phpunit
```

License
-------

[](#license)

MIT license

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity62

Established project with proven stability

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

Total

6

Last Release

4324d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5aebd62c372779a1223fca7819cdd898e82698e011b7617aaf822042710a55ec?d=identicon)[yuanqing](/maintainers/yuanqing)

---

Tags

stringregexinterpolationinterpolate

### Embed Badge

![Health badge](/badges/yuanqing-interpolate/health.svg)

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

###  Alternatives

[nette/utils

🛠 Nette Utils: lightweight utilities for string &amp; array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.

2.1k394.3M1.5k](/packages/nette-utils)[composer/pcre

PCRE wrapping library that offers type-safe preg\_\* replacements.

699313.8M34](/packages/composer-pcre)[spatie/regex

A sane interface for php's built in preg\_\* functions

1.1k17.1M59](/packages/spatie-regex)[coduo/php-to-string

Simple library that converts PHP value into strings

27112.7M10](/packages/coduo-php-to-string)[kwn/number-to-words

Multi language standalone PHP number to words converter. Fully tested, open for extensions and new languages.

4235.0M21](/packages/kwn-number-to-words)[opis/string

Multibyte strings as objects

7420.9M7](/packages/opis-string)

PHPackages © 2026

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