LoginSignup
1

More than 1 year has passed since last update.

.phpファイルをEUC-JPで作成すると文字化けしてしまう

Posted at

PHP5.6、文字コードEUC-JPで作られた古いサービスを、
PHP7.4、文字コードはそのままEUC-JPでバージョンアップさせる際に、
なぜか文字化けするなと思ったので、対処法をメモ。

拡張子が.phpのファイルは、文字コードが
・Shift_JIS
・EUC-JP
で、PHP5.6以上の場合文字化けしてしまうようです。

ApacheやPHPの設定を色々といじっても文字化けが直りませんでしたが、
ファイル先頭に以下を記載すると文字が正しく表示されました。

//Shift_JIS
<?php header("Content-Type: text/html;charset=Shift_JIS");?>

//EUC-JP
<?php header("Content-Type: text/html;charset=EUC-JP");?>

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1