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>');

preferences:
26.44 ms | 405 KiB | 5 Q