mb_convert_encoding "\" (backslash) and "~" (tilde) convert failed to Shift_JIS
Description
Backslash(\) and tilde(~) is convert to Shift_JIS (SJIS) using mb_convrert_encoding, But converted word is wrong word. Please see below code and 3v4l https://3v4l.org/nSVPB. Reproduced only PHP 8.1.
The following code:
<?php
var_dump(mb_convert_encoding(mb_convert_encoding("\\", "SJIS", "UTF-8"), "UTF-8", "SJIS"));
var_dump(mb_convert_encoding(mb_convert_encoding("~", "SJIS", "UTF-8"), "UTF-8", "SJIS"));
Resulted in this output:
string(3) "\"
string(3) "〜"
But I expected this output instead:
string(1) "\"
string(1) "~"
PHP Version
PHP 8.1.4
Operating System
No response
BTW, on the current implementation, SJIS-win is an alias of CP932, thus the return value of mb_list_encodings() never contains 'SJIS-win'. I have created a separate issue for this. #8308
Thanks for opening that issue. I have added some comments there.
Just read a few of the articles linked to above by @zonuexe, still remaining with a few more to read.
@alexdowad I have presented these references as a separate source to show that there is more than one type of character set conversion map like Japanese Shift-JIS Character Mapping - IBM Documentation. It seems that you have already implemented it based on the necessary knowledge. There may be little information available from these haystacks.
The discussion here seems to have fallen quiet.
I think the discussion in #8308 has convinced me that adjusting mappings for 'SJIS' to comply with JIS X 0201 was a mistake, and there are good reasons not to follow that specification.
I would like to submit a PR to revert that change, but first, are there any other mappings for SJIS or SJIS variants which are a concern for @youkidearitai or other interested parties who are following this thread? Or is it just SJIS 0x5C → Unicode and SJIS 0x7E → Unicode?
Sorry I mistake close this Issue. As far as I can see, it's just a matter of 0x7e and 0x5c. There may be something wrong, but I'd also like to see this massive overhaul of mbstring, so if I find something, I'd like to set up a new Issue, but how about it?
I also want to hear what Japanese people think.
I've gathered various opinions on this issue, Already most Japanese programmers see SJIS as a legacy character encoding, It seems that the general idea is to maintain backward compatibility. There seems to be no backward compatibility issues other than 0x5c and 0x7e, so I'd appreciate it if you could fix it.
@youkidearitai Absolutely, that will be done!
Thank you very much for reporting this issue and for following up on it.
Thank you, everyone!