str::template($string, $data = array())

A super simple string template engine, which replaces tags like {mytag} with any other string

  • $string (string)
  • $replace (array)
    An associative array with keys, which should be replaced and values.
  • return (string)

Example

<?php
$string = '{key1} is a {key2} {key3}';
$data = array(
  'key1' => 'Kirby'
  'key2' => 'file-based',
  'key3' => 'CMS',
);
$result = str::template($string, $data);

echo $result;

Result:

Kirby is a file-based CMS

Is something missing or incorrect? Edit this page on Github…