0

PHPheader('Content-type: text/html; charset=utf-8');を設定する必要がありますか

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

.htaccess-file で定義されていますか? .php ファイルもこのルールの影響を受けますか?

私はsettings.cfg.php-document を設定していますが、このコード行が本当に必要かどうか疑問に思っています。

必須ではないことはわかっていますが、エンド ユーザーは Apache サーバーの設定を変更するアクセス権がないため<meta charset="utf-8">、ドキュメントに残すことを強くお勧めします。index.phpしかし、それはクライアント側のコンテンツにのみ影響し、PHPによってサーバー側から作成されたフェッチされたコンテンツには影響しません-それが意味をなす場合...

編集: ここに私の index.php があります:
load.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>
4

1 に答える 1

1

ヘッダーはすでに htaccess を渡しているため (トリガーされている場合)、PHP で charset を再度定義する必要はありませんが、html 属性はそのままにしておく必要があります。

これを確認する良い方法は、端末などからの curl 要求でチェックし、生のヘッダーがどのように見えるかを確認することです (単純な curl -v http://example.com/で実行できます)。前後を確認し、違いがないか確認してください。

于 2013-04-27T23:44:51.667 に答える