Substitute X for Y
Solution 1:
This is probably the source of the confusion you noticed:
- “Substitute…for…”—first replaces second.
- “Substitute…with…”—second replaces first.
- “Replace…with…”—second replaces first.
- “Replace…by…”—second replaces first.
- etc.
“Substitute…for…” is an unusual case when it comes to the order of this sort of phrase, but actually the preposition is all-important. Just think of for as meaning in favour of or in place of.
Solution 2:
I agree with Jon and Henry. However, it should be noted that the use of to substitute X with Y is usually not recommended by style books: it is a blend of the old expressions to substitute X for Y and to replace X with Y. It may have emerged out of confusion between the two. You substitute the new thing for the old thing, and you replace the old thing with or by the new thing. There is also simply to substitute X, without a Y:
Petrochemical oil is a very useful type of fuel with a high energy yield; if we substitute vegetable oil, we may have less pollution, but we'll need larger fuel tanks.
This use of the verb to substitute X as above is quite common; you always substitute a new thing, vegetable oil. What you substitute it for is then implicit; in this case, it would be the petrochemical oil from the first clause. It fits with to substitute X for Y (you substitute the new thing), but it clashes with to substitute X with Y; that is another reason not to use the latter.
Solution 3:
The preposition controls the meaning. "Substitute X for Y" means what you think it does: the X will replace Y.
"Substitute X with Y", however, reverses the meaning: Y will replace X.