<?php
$closure = function($asterisk, $str) {
return "<$asterisk>".md5($str)."</$asterisk>";
};
// twig function name has a * wildcard
$function = new Twig\TwigFunction('md5_*', $closure,
['is_safe' => ['html']]);
// Using md5_* function in template
$templates = [
'template' => '{{ md5_strong("string") }}
<br>{{ md5_em("string") }}',
];
$loader = new Twig\Loader\ArrayLoader($templates);
$twig = new Twig\Environment($loader);
$twig->addFunction($function);
echo $twig->render('template');