3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = '<img src="data:image/png;base64,iVBORw0..="><img src="data:image/png;base64,iVBORw1..=">'; function deleteBase64_andReplace($start, $end, $replacement, $string) { $count = 0; $pattern = '|' . preg_quote($start, '|') . '(.*?)' . preg_quote($end, '|') . '|s'; while (strpos($string, $start) !== false) { return preg_replace_callback($pattern, function($m) use ($replacement, &$count) { return $replacement . ++$count;}, $string); } } $replacement = "image"; $stringResult= deleteBase64_andReplace("data:", "=", $replacement, $string); echo $stringResult;
Output for 7.4.0 - 7.4.33, 8.0.1 - 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 src="image1"><img src="image2">

preferences:
112.09 ms | 1239 KiB | 4 Q