3v4l.org

run code in 300+ PHP versions simultaneously
<?php $needle = ':Name'; $str = ":Name :Name_en"; echo "Leading word boundary\t\t" . preg_replace("#\b$needle\b#", '"Test"', $str); echo "\n---\n"; echo "No leading word boundary\t" . preg_replace("#$needle\b#", '"Test"', $str); echo "\n---\n"; echo "Leading non-word boundary\t" . preg_replace("#\B$needle\b#", '"Test"', $str);

preferences:
48.91 ms | 996 KiB | 5 Q