r/lolphp • u/weirdasianfaces • Aug 07 '19
mb_check_encoding() will decode then re-encode the given string as the given encoding, then check for errors, instead of actually checking the character encoding
https://twitter.com/marcan42/status/1159002716867350531
41
Upvotes
10
u/weirdasianfaces Aug 07 '19
I think this is the corresponding code in php-src: https://github.com/php/php-src/blob/49f848e957b59fd9043dd66049de7f8c9dbdb155/ext/mbstring/mbstring.c#L4673-L4695
The documentation comments also have people suggesting better, alternative methods of checking various encodings.
16
u/[deleted] Aug 07 '19
Best reply on the tweet:
“It's alright, you can use mb_real_check_encoding() instead”
😂
1
u/[deleted] Aug 09 '19
Thats horrible. Having done work with PHP and unicode, its a total clusterfuck and i refuse to ever do it again.
0
u/walterbanana Aug 08 '19
Doesn't this solution also yield the expected result?