2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PHPでどうやってコンテンツのEncodingをチェック出来る?

Posted at

システムを開発する時に、「ファイルのコンテンツ」を検証する場合も有るかもしてません。
CSVかExcelのコンテンツをチェックする為に、「mb_detect_encoding」をよく使いますので、メモ行ったします。
他の仕方があれば、コメントして頂けば、幸せです。

下は「Shift JIS」を検証の例です。


$file_content = file_get_contents($file);
$encodings    = array('SJIS-win', 'UTF-8', 'UTF-16');
if (mb_detect_encoding($file_content, $encodings) !== 'SJIS-win') 
{
    throw new Exception(__("File encoding must be Shift JIS."));
}

// $convertCt   = mb_convert_encoding($file_content, 'UTF-8', 'SJIS-win');

:relaxed:よろしくお願いします。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?