Charcter encoding and PHP

2019-06-13 17:53发布

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?

2条回答
一纸荒年 Trace。
2楼-- · 2019-06-13 18:33

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.

查看更多
beautiful°
3楼-- · 2019-06-13 18:37
  1. Make sure you language files are utf8,
  2. make sure your HTML files and template are utf8,
  3. 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

查看更多
登录 后发表回答