I need compare two string. Visually they compare, but var_dump result other. Help me please.
string(8) "СИ.pdf" string(7) "CИ.pdf"
How correct compare him?
I need compare two string. Visually they compare, but var_dump result other. Help me please.
string(8) "СИ.pdf" string(7) "CИ.pdf"
How correct compare him?
Use mb_convert_encoding() to convert both versions to something reasonable (UTF8 for example) then use mb_strstr() to do the comparison.
Your first string, "СИ.pdf", uses the Cyrillic capital letter Es while the second, "CИ.pdf", has the Latin capital letter C. These are homoglyphs, and a way to check for them is to use Spoofchecker::areConfusable(), e.g.
$a = "СИ.pdf";
$b = "CИ.pdf";
var_dump(
$a === $b,
(new Spoofchecker())->areConfusable($a, $b)
);
Outputs:
bool(false)
bool(true)
Spoofchecker is from PHP's intl extension which is a wrapper for the ICU library. ICU's spoof checking is based on Unicode Technical Report #36 and Unicode Technical Standard #39.
most likely there are some non printable characters in the string
check out the following : PHP: How to remove all non printable characters in a string?