2013-04-27 115 views
0

PHP是必要header('Content-type: text/html; charset=utf-8');是在htaccess中设置字符集时需要设置php字符集吗?

AddDefaultCharset utf-8 
<IfModule mod_mime.c> 
    AddCharset utf-8 .php .html .xml .css .js .json 
</IfModule> 

在我的.htaccess文件被定义为集? .php文件是否受此规则影响?

我正在创建一个settings.cfg.php -document,并想知道我是否真的需要这行代码 - 如果它会有点矫枉过正。

我知道这并不是必需的,但强烈建议您将<meta charset="utf-8">保留在index.php-文档中,因为最终用户无权修改我的Apache服务器设置。但是,这只会影响到客户端的内容,而不是内容获取OG从服务器端用PHP创建 - 如果那所做的任何SENCE ...

编辑:这是我的index.php:
负载。 initialize.php需要我settings.cfg.php文件,在最高层......

<?php require_once 'initialize/load.initialize.php'; ?> 
<!DOCTYPE html> 
<head> 
<meta charset="utf-8"> 
    ... 
</head> 
<body> 
<!-- 
    this document includes page -header, -navigation, -content and -footer, 
    where the content-part is just including other .php content pages or fetching content from database. 
--> 
<?php require 'template/load.template.php'; ?> 
</body> 
</html> 

回答

1

你的头就已经被传递htaccess的(如果它被触发),你不需要定义字符集再次在PHP中,但HTML属性仍然很好保持。

确认此问题的一个好方法是检查来自终端等的curl请求并查看原始页眉的外观(简单的curl -v http://example.com/将会这样做)。检查之前和之后,检查是否有任何差异来确认。

+0

Okey。这是我的。并感谢有关卷发请求槽终端的提示。 – ThomasK 2013-04-27 23:56:28