0

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?

Maksim Borodov
  • 279
  • 1
  • 6
  • 12
  • 2
    Most likely the strings are in different encoding. You will have to find out why that is, so that you can prevent such thing in future. Do _not_ search for some automatic encoding conversion, _that will not work_. Use a `hexeditor` if you want to understand what you see. – arkascha Mar 26 '17 at 10:20
  • you have to [`setlocale`](http://php.net/manual/en/function.setlocale.php) – Deadooshka Mar 26 '17 at 10:26

3 Answers3

1

Use mb_convert_encoding() to convert both versions to something reasonable (UTF8 for example) then use mb_strstr() to do the comparison.

mayersdesign
  • 4,657
  • 4
  • 31
  • 46
0

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.

user3942918
  • 24,679
  • 11
  • 53
  • 67
-1

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?

Community
  • 1
  • 1
Arie
  • 96
  • 4