- str_replace: documentation ( source)
- array_walk: documentation ( source)
<?php
function interpolate($str, $data) {
// /var/storage/images/strip/' .$hash . '/tn_' . $n . '.jpg';
array_walk($data, function($value, $key) use ($str) {
$str = str_replace('{{' . $key . '}}', $value, $str);
});
return $str;
}
$str = '/var/storage/images/strip/{{hash}}/tn_{{n}}.jpg';
echo interpolate($str, array('hash' => '0238de39s82u4d30238de39s82u4d3', 'n' => 1));