3v4l.org

run code in 300+ PHP versions simultaneously
<?php define('SITE_URL', 'http://example.com'); $vars = [ 'SITE_URL' => SITE_URL ]; $template = '<p class="card mb-4 shadow-sm"><img src="{{ SITE_URL }}/assets/images/blog/php.png" alt="php" title="php"></p>'; // match any single word with _ or -, with spaces either side or not // e.g: {{key}} or {{ key }} or {{key-foo}} or {{ key-foo }} // not {{ a b c }} $str = preg_replace_callback("/\{\{[ ]{0,}([\w\_-]{1,})[ ]{0,1}\}\}/", function ($match) use ($vars) { return array_key_exists($match[1], $vars) ? $vars[$match[1]] : ''; }, $template); echo $str;
Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
<p class="card mb-4 shadow-sm"><img src="http://example.com/assets/images/blog/php.png" alt="php" title="php"></p>

preferences:
92.83 ms | 408 KiB | 5 Q