I am trying to compare a value submitted as a POST to an internal string. They are both utf8 encoded. This is the code
echo $_POST["province"] . "\n";
setlocale(LC_COLLATE, "fr_CA");
echo strcoll($_POST["province"], "Québec");
This code echos the following:
Québec
-38
strcoll should return 0 if the string match, not -38. In other words, the comparison fails. How do I compare two utf8 string that are identical to a human reader, but might be encoded differently? I have tried Normalizer:normalize, the common "==" operator, looked at multibyte php extension (but there seem to be no compare functions??) and nothing worked thus far for me.
utf8_decode
to ensure that the strings you're checking are in the same encoding.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.