Search code examples
phpstringcharmd5ord

ord, md5 shows different behaviour on @


I used ord to check @ and @‪ are same char. But ord output the same value while md5 does not.

php -a
Interactive shell

php > echo ord('@');
64
php > echo ord('@‪');
64

php > echo md5('@');
518ed29525738cebdac49c49e60ea9d3
php > echo md5('@‪');
e6124653b6620abe51d7c401a7644674
php >

Here is the screenshot,
enter image description here


Solution

  • Your second one is @ followed by U+202A - LEFT-TO-RIGHT EMBEDDING. As they are different strings, naturally they have different MD5 encodings.

    php > echo md5("@\u{202a}");
    e6124653b6620abe51d7c401a7644674