PHP包含html页面字符集问题 [英] PHP include html page charset problem
问题描述
使用以下代码查询mysql数据库后,我生成了一个html文件:
after querying a mysql db using the code below i have generated an html file:
$myFile = "page.htm";
$ fh = fopen($ myFile,'w')或die(无法打开文件"); fwrite($ fh,$ row ['text']); fclose($ fh);
$fh = fopen($myFile, 'w') or die("can't open file"); fwrite($fh, $row['text']); fclose($fh);
在msql数据库上,使用utf8_general_ci对文本进行编码. 但是我需要将其包含在php网页中,如下所示:
On the msql db the text is encoded using utf8_general_ci. But i need to include it in a php web page as shown below:
<?include('page.htm');?>
请记住,PHP网页在标头上使用utf8字符集:
bearing in mind that the php web page uses utf8 charset on the header:
<meta http-equiv="content-type" content="text/html; charset=utf8" />
现在,如果我在db上写一些带有重音符号(èà)或引号字符的字母,然后直接打开page.htm,然后在db上我就看到一切正常,但是当我在php上查看时在页面上,我看到一个问号-字符,而不是我最初想要的字符. 为什么?! 预先感谢!
Now if i write on the db some letters with grave accent (è à ì) or a quote character and i open directly page.htm and on the db i see it all looking ok, but when i view it on the php page i see a question mark � character instead of those I originally wanted. Why?! Thanks in advance!
推荐答案
META字符集并不总是可以解决问题.确保您的IDE保存了真实的UTF-8文件.对于Dreamweaver中的示例,请按CTRL-J,然后选中标题/编码"选项.
META charset isn't always solve the problem. Make sure your IDE saving real UTF-8 files. For exanple in Dreamweaver press CTRL-J then check Title/Encoding options.
这篇关于PHP包含html页面字符集问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!