Escaping '.' solved the problem
<?php $text1 = "eggs"; $l = 'e.g.'; $ll = str_replace(".", "\.", $l); $text2 = preg_replace(["/\b{$ll}\b/", ], ["<b>{$ll}</b>", ], $text1);