<p>Here's the goal: to replace all standalone ampersands with &amp;amp; but NOT replace those that are already part of an HTML entity such as &amp;nbsp;.</p>

<p>I think I need a regular expression for PHP (preferably for preg_ functions) that will match only standalone ampersands. I just don't know how to do that with preg_replace.</p>

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).
Much easier and faster than a regex.