问题
I'm building a multilingual website that uses PHP to load language files. Paragraphs in the language file are set in define() constants. After opening page in the browser I get a bunch of characters like "?". In the markup I have encoding set to utf-8. What can be done to make it work other than replacing all unknown characters with html character entities?
回答1:
- Make sure you language files are utf8,
- make sure your HTML files and template are utf8,
make sure you add the following tag to your page
< meta http-equiv="Content-Type" content="text/html; charset=UTF-8" / >
as long as your data is utf8, the template and html files are utf8 and you explicitely specify the html page is utf8, it should work.
EDIT: the code embedding thing is a bit broken today... have to insert a space at the tag opening.weird
回答2:
header('Content-Type:text/html; charset=UTF-8');
use this line on the top of your PHP code to send header; also helps with validation of dynamic pages to get rid of utf warning.
来源:https://stackoverflow.com/questions/4236661/charcter-encoding-and-php