Last active
September 19, 2017 16:36
-
-
Save masakielastic/c2808bba448df4ff3f3110e7d3180b2d to your computer and use it in GitHub Desktop.
0x0 から 0xff の範囲のバイトに対して mb_convert_encoding が無効なバイトをどのように置き換えるのかを確認します。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$enc = "cp932"; | |
for ($cp = 0; $cp < 0x100; $cp++) { | |
$c = chr($cp); | |
$ret = mb_convert_encoding($c, $enc, $enc); | |
echo | |
bin2hex($c), " ", | |
bin2hex($ret), " ", | |
mb_check_encoding($c, $enc) ? "true":"false", | |
PHP_EOL; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enc = "cp932" | |
(0..0xff).each do |cp| | |
c = [cp.to_s(16)].pack("H*").force_encoding(enc) | |
ret = c.scrub | |
puts "#{c.unpack("H*")[0]} #{ret.unpack("H*")[0]} #{c.valid_encoding?}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment