0
0

More than 3 years have passed since last update.

PHPでShift-JISのコードポイントを確認する

Posted at

とある案件でShiftJISのコードポイントが確認したかったので、その際の処理を( ..)φメモメモ
大人の事情でPHP5.3とかいう微妙なバージョンだったけど、たぶん7系でも動くはず…

$str= 'あいうえお';

// 文字列を1文字ずつ配列に分割 (-1は無制限(デフォルト値)、PREG_SPLIT_NO_EMPTYは配列前後に入る空白文字の除外)
$chArray = preg_split('//u', $str, -1, PREG_SPLIT_NO_EMPTY);

foreach($chArray as $ch){
  // UTF8→SJISに変換
  $ch_SJIS = mb_convert_encoding($ch, 'SJIS-win', 'auto');
  // SJISのコードを出力
  echo bin2hex($ch_SJIS).PHP_EOL;
}
die;
0
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
0
0