php - replace string but not a specific word that contains that string -
suppose have string
$string = 'this gal_s, not 1_s not 2_s not 3_s'; $find = '_s'; $replace = '';
i woul return
"this gal_s, not 1 not 2 not 3"
so word gal_s
not affected
is possible?
you can use preg_replace negative lookbehind this:
$repl = preg_replace('/(?<!\bgal)_s/', '', $str);
Comments
Post a Comment