1
4

2 回答 2

2

You're entering the domain of character encoding. It confuses many people so here are some guidelines:

Since you're dealing with HTML you can always use htmlentities. This will give you something like; &abc; or Ӓ. These characters will always display correctly.

Another approach is to use characterset encoding. This means you have to make sure all your characters are output in the same character encoding and you give the correct character encoding hints to the browser.

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

To force a browser to use UTF-8. You can substitute for ISO-8859-1 is that is your preferred encoding.

Then, if you all your input is UTF-8 your output should also be UTF-8. If it's not, convert it. utf8_encode will convert a string to UTF-8.

于 2013-02-08T17:06:55.277 回答
1
var_dump( htmlentities('foo ®®', ENT_QUOTES, "UTF-8") );

Make sure your source file is UTF-8 encoded.

Most IDEs offer a "character set" option in the "Save As" dialog or somewhere in the file's options.

于 2013-02-08T18:54:02.130 回答