LoginSignup
2
0

More than 5 years have passed since last update.

phpで文字コードEUCのpostgresのデータの文字化け

Posted at

今時EUCでphp書いてるなんて人はまずいないだろうから、これからの人には何の役にも立たない情報だが。

まあ今後、古いソースを直さないといけないことがないとも限らない。

データベースがpostgresでデータはEUCで保存されている。

それをphpで読み込んで出力するHTMLは

content="text/html; charset=EUC-JP"

としてEUCで処理されている。

すると、髙木さんのはしご高が化ける。

ターミナルではちゃんと読めるのにねえ。

ということで以下のようにするとよい。

$username にDBから読み込んだ値を入れておいて、

$username = mb_convert_encoding($username, "UTF-8", "eucjp-win");
$username = mb_convert_encoding($username, "CP51932", "UTF-8");

一旦UTF-8にしてからもう一回変換するということなんだが。。。。

2
0
0

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
2
0