- str_replace: documentation ( source)
<?php
$html = '<{$headtype} class="{$class}">{$text}</{$headtype}>';
$array['headtype'] = 'h1';
$array['class'] = 'classname';
$array['text'] = 'the title';
foreach ($array as $key => $value) {
$html = str_replace('{$'.$key.'}', $value, $html);
}
echo $html;