Charcter encoding and PHP

两盒软妹~` 提交于 2019-12-08 10:23:37

问题


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:


  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




回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!