Here\'s the goal: to replace all standalone ampersands with & but NOT replace those that are already part of an HTML entity such as .
I think I nee
You could always run html_entity_decode before you run htmlentities? Works unless you only want to do ampersands (and even then you can play with the charset parameters).
html_entity_decode
htmlentities
Much easier and faster than a regex.