3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<HTML <h1>Or Any Other tags except img or nothing</h1> <span>stuff</span> <img src="{{media url=&quot;image_name.png&quot;}}" alt="image_test" /> <div>more stuff</div> <h1>Or Any Other tags except img or nothing</h1> HTML; function alterateContent(string $html, string $imageFileName, string $replacement): string { $imageFileName = preg_quote($imageFileName, '/'); return preg_replace("/<img\h+src=\"{{media url=&quot;{$imageFileName}&quot;}}\".*?\/>/", $replacement, $html); } echo alterateContent($html, 'image_name.png', '<b>Hi test</b>');
Output for 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.27, 8.4.1 - 8.4.14
<h1>Or Any Other tags except img or nothing</h1> <span>stuff</span> <b>Hi test</b> <div>more stuff</div> <h1>Or Any Other tags except img or nothing</h1>

preferences:
156.07 ms | 407 KiB | 5 Q