I am trying to search and replace into a string, I have 2 problems 1. i need to check if term is inside a tag "term" - and do nothing in this case. 2. I need to make sure I am replacing a complte word and not cutting this word:
function str_replace_first($from, $to, $content)
{
$from = '/'.preg_quote($from, '/').'/';
return preg_replace($from, $to, $content, 1);
}
example:
echo str_replace_first('good','bad','goodmorning');
the result: badmorning // I need the script not to replace if we are cutting a word, and do the replace if we are changing a whole word thanks