I\'m using preg_replace in PHP to find and replace specific words in a string, like this:
$subject = \"Apple apple\";
print preg_replace(\'/\\bapple\\b/i\',
This is the solution that I used:
$result = preg_replace("/\b(foo)\b/i", "$1", $original);
In the best words that I can I'll try explain why this works: Wrapping your search term with () means I want to access this value later. As it is the first item in pars in the RegEx, it is accessible with $1, as you can see in the substitution parameter