Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
<?php // Template variable substitution function renderTemplate(string $template, array $vars): string { return preg_replace_callback( "/\{\{\s*(\w+)\s*\}\}/", function (array $match) use ($vars): string { return htmlspecialchars($vars[$match[1]] ?? "", ENT_QUOTES, "UTF-8"); }, $template ); } echo renderTemplate("Hello, {{ name }}! You have {{ count }} messages.", [ "name" => "Alice", "count" => "3", ]); // "Hello, Alice! You have 3 messages."
Result
Open