Skip to content

Instantly share code, notes, and snippets.

@tanakahisateru
Last active June 19, 2018 11:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tanakahisateru/b9e4e65502282b08a83a2c74baff446d to your computer and use it in GitHub Desktop.
Save tanakahisateru/b9e4e65502282b08a83a2c74baff446d to your computer and use it in GitHub Desktop.
入力した波ダッシュが全角チルダに化けるまたはその逆について
<?php
$wave = "\u{301C}";
$tilde = "\u{FF5E}";
// EUC-JP has no different character for wavy dash and full width tilde
$eucWave = mb_convert_encoding($wave, 'euc-jp', 'utf-8');
$eucTilde = mb_convert_encoding($tilde, 'euc-jp', 'utf-8');
assert($eucWave == $eucTilde);
// euc-jp to utf-8: always wavey dash
$revertedEucWave = mb_convert_encoding($eucWave, 'utf-8', 'euc-jp');
$revertedEucTilde = mb_convert_encoding($eucTilde, 'utf-8', 'euc-jp');
assert($revertedEucWave == $wave);
assert($revertedEucTilde == $wave);
// eucJP-win to utf-8: always full width tilde
$revertedEucWinWave = mb_convert_encoding($eucWave, 'utf-8', 'eucJP-win');
$revertedEucWinTilde = mb_convert_encoding($eucTilde, 'utf-8', 'eucJP-win');
assert($revertedEucWinWave == $tilde);
assert($revertedEucWinTilde == $tilde);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment