Now that the /e modifier is considered deprecated in preg_replace, you can use a negative lookahead to replace unescaped ampersands with & without throwing warnings:
$str = preg_replace('/&(?!;{6})/', '&', $str);
You probably should have been doing this before /e was deprecated, actually.