问题
I'm making a website that is in Croatian, and I need to use signs like: "č", "ć", "ž", "đ" and "š". They are currently displayed as little boxes.
Info:
- I use Notepad ++.
- I set the encoding there to UTF-8.
- I put the following line of HTML in:
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
However, it does not work. Even Notepad ++ can't display my characters using UTF-8, so that would suggest that I should probably use something else...
回答1:
http://webdesign.maratz.com/lab/utf_table/
Use HTML entities, for example
- č :
č
- ž :
ž
回答2:
This sounds more like a font issue than a character encoding issue. If it were a character encoding issue, the characters would most likely be displayed as 2+ ASCII characters. The boxes, however, typically mean the character encoding is correct, but that specific character is not available in the font being used (which is especially common with lesser-used fonts). This would explain why it's behaving incorrectly in both the website and Notepad++.
To fix the issue, simply use a different font in your editor and website.
Note: I recommend a widely used font for the best chance of it working. Specifying a generic name in the website (e.g. serif
or sans-serif
) will probably have even better results, as the OS/browser would decide on the best font to use.
回答3:
In short, be consistent about your character encoding throughout.
- Configure your editor to save in the encoding you want
- If you use any server side programming, make sure it isn't transcoding your data
- If you use a database, make sure it is configured to use the same encoding
- Configure your server to emit a Content-Type header that specifies that encoding
- Use the meta tag in your question
The W3C provides useful material on encodings that starts here.
回答4:
A useful site for special characters and their ASCII-codes: CopyPaste Character
To 'type' them, use the alt codes.
However, to use them in your site, you'll better use the HTML codes like you can find on CPC
回答5:
As a test, try this:
<span style="font-family:Arial Unicode MS">
č ć ž đ š
</span>
You should be able to see your characters correctly.
回答6:
I've just copied and pasted a line from your question along with your meta tag, placed it into a plain text file in vi
.
It works just fine - all characters are displayed fine: http://www.dusystems.com/tmp/1.html
If you can't do the same with your editor then the problem is with the editor and not character sets and encodings.
If you're on Windows you can use its built-in Notepad to edit UTF-8 files. Open Notepad, type all of your special characters, add the meta tag. When doing Save As select UTF-8 from the Encoding drop-down in the dialog. Save as something.html and open in IE. It will 100% work.
来源:https://stackoverflow.com/questions/9219271/how-to-make-the-website-show-signs-like-%c4%8d-and-%c4%87