I want to replace a word with PHP preg_replace. It should not replace the word if the characters /> exist before this word.
i.e.
this should be replaced if matched
$word = "foo";
this should not be replaced if matched
$word = "/>foo";
I want to replace a word with PHP preg_replace. It should not replace the word if the characters /> exist before this word.
i.e.
this should be replaced if matched
$word = "foo";
this should not be replaced if matched
$word = "/>foo";
Here you are ;-)
(?<!/>)foo
good luck
if ($word[0] != '/' && $word[1] != '>') {
$new_string = str_replace($word, $replace, $string);
}