とある案件で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;