UTF-8 html without BOM displays strange characters

前端 未结 2 1136
北海茫月
北海茫月 2021-01-11 22:11

I have some HTML which contains some forign characters (€, ó, á). The HTML document is saved as UTF-8 without BOM. When I view the page in the browser the forign characters

相关标签:
2条回答
  • 2021-01-11 22:55

    You are probably not specifying the correct character set in your HTML file. The BOM (thanks @Jukka) sends the browser into UTF-.8 mode; in its absence, you need to use other means to declare the document UTF.8.

    If you have access to your server configuration, you may want to make sure the server isn't sending the wrong character set info. See e.g. How to change the default encoding to UTF-8 for Apache?

    If you have access only to your HTML, adding this meta tag in your document's head should do the trick:

    <meta http-equiv='Content-Type' content='Type=text/html; charset=utf-8'>
    

    or as @Mathias points out, the new HTML 5

    <meta charset="utf-8"> 
    

    (valid only if you use a HTML 5 doctype, against which there is no good argument any more even if you don't use HTML 5 markup.)

    0 讨论(0)
  • 2021-01-11 22:56

    Insert <meta charset="utf-8"> in <head>.
    Or set the header Content-Type: text/html;charset=utf-8 on the server-side.

    You can also do add in .htaccess: AddDefaultCharset UTF-8 more info here http://www.askapache.com/htaccess/setting-charset-in-htaccess.html

    0 讨论(0)
提交回复
热议问题