Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaScript and php encoding output are inconsistent #2

Open
huanshiwushuang opened this issue Nov 1, 2021 · 2 comments
Open

JavaScript and php encoding output are inconsistent #2

huanshiwushuang opened this issue Nov 1, 2021 · 2 comments

Comments

@huanshiwushuang
Copy link

Use JavaScript: Base62x.encode('哈')
output: 'vPE8'

But,

Use PHP: Base62x::encode('哈')->get();
output: 'vU5'

Hope to get your help, thanks

@huanshiwushuang
Copy link
Author

maybe not support chinese ?

@wadelau
Copy link

wadelau commented Nov 1, 2021

I had troubleshooted into the issue and found that the point was mb_str_split funtion which is a built-in function after PHP-7.4.

The Chinese character "哈" with UTF-8 format will be split into a Character-Array as ['哈'] by mb_str_split.
However, the same Chinese character will be split into a Byte-Array as [229, 147, 136] by str_split, which is expected in src/Encoding/Base62x::encode.

We have not figured out why the author of this repo changed the function from str_split to mb_str_split.

My advice is to use str_split for byte-array, mb_str_split for character-array.
Byte is equivalent to character in ASCII, so American-European may have no sense of such issues.
In fact, one character may contains one byte, two bytes, three bytes or even more with UTF-8 charset.

The suggestion is to replace mb_str_split with str_split in src/Encoding/Base62x for test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants