<?php function my_replace (string $fullText, string $searchText) { $searches = str_replace(' ', '|', $searchText); return preg_replace("/\b(?:$searches)\b\K/i", "<-", $fullText); } echo my_replace('A week ago, Elvis left the Building', 'elvis left');
You have javascript disabled. You will not be able to edit any code.