3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = '<p id="keepthis"> text</p><div id="foo">text</div><div id="bar">more text</div><a id="red"href="page6.php">Page 6</a><a id="green"href="page7.php">Page 7</a>'; echo preg_replace_callback( '/(?<=<div|<a)( *id="[^"]+")/i', function ($match) { return " "; }, $string );

preferences:
55.68 ms | 402 KiB | 5 Q