The Loner flaw in Dragon vol. 327 does exactly that, trading an animal companion (or familiar) for a feat. Note that flaws are an optional variant system, and that characters only get to choose up to two flaws (for up to two extra feats), usually at 1st level.
The druid has a few alternate options, though none lose just the animal companion, and none offer a feat:
Unearthed Arcana—druidic avenger, lose animal companion and spontaneous spellcasting in exchange for rage and fast movement.
Player’s Handbook II—shapeshift variant, lose animal companion and wild shape in exchange for a more minor and simple, at-will polymorph effect.
Races of Eberron–shifter druid racial substitution level, can get beast spirit instead of animal companion at 1st.
The ranger also has several options, including at least one excellent option:
Champions of Valor—shooting star, bonus spells and improved spellcasting replaces animal companion, solid choice. Would be the best choice, except that mystic ranger from Dragon vol. 336 exists and is far better, so you can get improved spellcasting and solitary hunting (below).
Complete Champion—spiritual guide, skill bonuses and 1/day commune with nature instead of animal companion.
Dragon vol. 347—solitary hunting, replace animal companion with the ability to apply favored enemy bonuses to attack rolls. An excellent choice.
Exemplars of Evil—celestial slayer, for evil rangers, lose animal companion and woodland stride for SR vs. good spells and a bonus on crit vs. good creatures
Player’s Handbook II—distracting attack, instead of animal companion. Any enemy you attack is considered flanked for the rest of the round.