<commit_before># Interpolate.php [![Packagist Version](http://img.shields.io/packagist/v/yuanqing/interpolate.svg)](https://packagist.org/packages/yuanqing/interpolate) [![Build Status](https://img.shields.io/travis/yuanqing/interpolate.svg)](https://travis-ci.org/yuanqing/interpolate) [![Coverage Status](https://img.shields.io/coveralls/yuanqing/interpolate.svg)](https://coveralls.io/r/yuanqing/interpolate)

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):

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

## Usage

1. Tags are enclosed in single 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 above example).

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:

    ```php
    $i = new \yuanqing\Interpolate\Interpolate;
    $tmpl = '{baz}';
    $data = array(
      'foo' => 'Hello',
      'bar' => 'World',<commit_msg>Document the double brace option<commit_after># Interpolate.php [![Packagist Version](http://img.shields.io/packagist/v/yuanqing/interpolate.svg)](https://packagist.org/packages/yuanqing/interpolate) [![Build Status](https://img.shields.io/travis/yuanqing/interpolate.svg)](https://travis-ci.org/yuanqing/interpolate) [![Coverage Status](https://img.shields.io/coveralls/yuanqing/interpolate.svg)](https://coveralls.io/r/yuanqing/interpolate)

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):

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

## Usage

1. By default, tags are enclosed in single braces. To use double braces (*a la* Mustache), simply pass `true` to the constructor:

    ```
    $i = new \yuanqing\Interpolate\Interpolate(true);
    ```

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 above example).

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:

    ```php
    $i = new \yuanqing\Interpolate\Interpolate;
    $tmpl = '{baz}';
    $data = array(
      'foo' => 'Hello',
      'bar' => 'World',
{'fraction_non_alphanumeric': 0.16178943827783385, 'fraction_numerical': 0.0026908846283215607, 'mean_word_length': 4.291814946619217, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 12, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '34781', 'n_tokens_mistral': 1065, 'n_tokens_neox': 1019, 'n_words': 259}