<?php

$text = "Hello there {{{name}}}!\nDid you try to {{{hack}}} me?";

$pattern = '/{{{([a-zA-Z_]+)}}}/';

$text = preg_replace_callback($pattern, 'produce_replacement', $text);
echo $text;

function produce_replacement($match) {
    $producerName = 'evaluate_'.strtolower($match[1]);
    return function_exists($producerName) ? $producerName() : null;
}

function evaluate_name() {
    return "Joe";
}
