问题
Im currently making a file that some have to download and upload. The file have som differents encodings and it only works if the file is opened with UTF-8 with BOM.
Currently im using this simple header header('Content-Type: text/html; charset=utf-8'); but how can i change the settings so file file would be seen as UTF-8 with BOM.
Hoping for some help. Thanks!
回答1:
There's absolutely no need to include a BOM in an HTML file. (If it really includes different encodings, then a UTF-8 BOM would be broken, so it sounds like you're a bit confused.)
If you expect the file to be saved to disk and used in places where UTF-8 isn't expected, you could add a meta element to indicate the encoding as well:
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
If in fact you are using a different encoding than UTF-8, then rather than a BOM, just change the value in the meta attribute.
If you really must have a BOM in there then you'll need to make sure that it's first thing you output, e.g.
echo "\xEF\xBB\xBF";
See How can I output a UTF-8 CSV in PHP that Excel will read properly? for an example where that actually makes sense.
来源:https://stackoverflow.com/questions/17424611/header-content-type-charset-utf-8-with-bom