When using backtracking, you want the $2 to be passed to regex engine. Though, normally php will evaluate it.
So, to ensure it's passed as a dollar sign and not as an evaluated variable you need to add a slash before it. Like so...
Code:
preg_replace("/(http:\/\/|http:\/\/www.|www.|)amazon.de\/exec\/obidos\/ASIN\/([A-Z0-9]+)([^\"\n]*?)\s+/i","http://www.amazon.de/exec/obidos/ASIN/\$2/$id ",$string);
Hope this helps,
Modin