All responses from my Symfony 2 application all have this header line:
Content-Type: text/html
So my browser assumes the output charset is ISO-8859-1. I would like the header to say:
Content-Type: text/html; charset=utf8
instead. I know I can do this manually for every response like this:
$response->setCharset('UTF-8');
But that would be incredibly redundant since my application has lots of controls and will only ever output UTF-8. I have searched in vain for a Symfony configuration setting that controls the default charset. I found framework.charset
but that seems to be unrelated, and is UTF-8 by default anyway.
How do I get Symfony to specify my charset in all responses?
My thoughts
I know this isn't too much of a problem (most of the time) since I can specify the charset explicitly in both HTML and XML. The issue is when I'm service plain text or JSON, or if I'm dumping variables using var_dump
. In both cases, all non-ASCII symbols are scrambled as my browser ventures an erroneous guess.
My backup solution is to subclass the response class and put $this->setCharset('UTF-8')
in the constructor.