What is the (default) encoding for the function md5() in PHP?

前端 未结 2 1195
不知归路
不知归路 2020-12-21 15:50

When I tested this little script:

$str = \"apple\";

echo md5($str);

The result matched the result of doing md5 using utf8 (tested using C#

相关标签:
2条回答
  • 2020-12-21 16:08

    Simply md5() will always give the same encoding. If you cannot trust it, Simply you can encode data in Database itself.

    0 讨论(0)
  • 2020-12-21 16:17

    The encoding of a string literal is whatever encoding you saved the source file in. If you saved this php file in UTF-16, you would get a different result, that is, if the code even runs.

    There is no unified or managed encoding in PHP. Strings in PHP can be in any encoding, in other words, they are equivalent to byte arrays of languages that have more abstract string type.

    0 讨论(0)
提交回复
热议问题