3v4l.org

run code in 300+ PHP versions simultaneously
<?php $homepage = "https://example.com/"; $html = '<img class="drt" src="100.png"><img src="../101.png"><img src="/102.png"><img src="103.png">'; $check_img = preg_match_all("/<img .*?(?=src)src=\"([^\"]+)\"/si", $html, $m); foreach ($m[1] as $img){ if (strpos($img, $homepage) == false) { $old_img = $img; $html = str_replace($old_img, $homepage.basename($old_img), $html); } } echo $html;
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.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
<img class="drt" src="https://example.com/100.png"><img src="https://example.com/101.png"><img src="https://example.com/102.png"><img src="https://example.com/103.png">

preferences:
95.45 ms | 1530 KiB | 4 Q