php - Reg exp to replace ampersands but not html entities -
in code below want replace plain ampersands "and" while ignoring ampersands being used part of html entities (ex: ")
i've tested expression &(?!([\w\n]{2,7}|#[\d]{1,4});) on @ http://www.gskinner.com/regexr/ , matches want.
however, when run code, results blank.
$content = "" apples & oranges ""; $content = preg_replace("/&(?!([\w\n]{2,7}|#[\d]{1,4});)/g","and",$content); echo $content;
is approach flawed somehow or have syntax issue?
remove g
flag , should work fine.
note seem me you'd expect , ampersand surrounded spaces, following simplified solution:
$content = preg_replace("/\s/&\s/"," , ",$content);
although realise might allow mistyped text cause encoding errors. if there space missing.
Comments
Post a Comment