while ( (ord($encoding[$n - $length]) & 0xC0) != 0xC0);

Should'nt it be :

while ( (ord($encoding[$n - $length]) & 0xC0) != 0x80);

Comments

chx’s picture

Status: Active » Closed (works as designed)

No, the first UTF8 byte always has the two topmost bits flipped. It would be == 0x80 if you want to do that but honestly isnt this more readable?