The third parameter is just to tell htmlspecialchars() not to mess up Unicode strings. You need to tell htmlspecialchars() what the input encoding is. Consequentially, that is also the encoding used in the output.
Remember that PHP does not support Unicode, so it does not care about what charset you are using. That parameter in htmlspecialchars() is only used to tell PHP not to mess up with your bytes.