简体   繁体   中英

Header Content Type Charset UTF-8 with BOM

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!

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, eg

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM