PHP string comparison problem

I have two lines with seemingly identical values. One is stored as a key in the array, and the other in another other array. I compare the two using ==, === and strcmp. Everyone sees them as different lines. I am doing var_dump and that is what I get.

string(17) "Valentine’s Day" 
string(15) "Valentine Day"

Does anyone know why the first line will be 17 characters and the second 15?

Update: this is a little more obvious when I pasted it from my editor, the font of which made two different apostrophes almost indistinguishable.

+3
source share
3 answers

The first line contains the Unicode character for the apostrophe, and the second line has the usual ASCII character.

The Unicode character takes up more space.

PHP ord() , , :

echo ord("’"); //226 This is just the first 2 bytes (see comments below for details from ircmaxell)
echo ord("'"); //27
+7

@Mark , (’ - , UTF-8, ' - ). ASCII ( ISO-8859-1) iconv, :

echo iconv('utf-8', 'ascii//TRANSLIT', $str);

. ASCII latin1. //IGNORE, .

+1

! = '

primarily. if you want this not to be a problem, you can do something like this.

if (str_replace ('', '\' ', "Valentines Day") == "Valentine's Day") {

0
source

Source: https://habr.com/ru/post/1783294/


All Articles