3v4l.org

run code in 300+ PHP versions simultaneously
<?php $strings = [ "This is a word", "<-#word#->", "<-#<-#<-#word#->#->#->", ]; $p = "word"; foreach ($strings as $string) { $string = preg_replace("/(?<!<-#)($p)(?!#->)/i", '<-#$1#->', $string); echo $string . PHP_EOL; }

preferences:
65.8 ms | 402 KiB | 5 Q