What is the (default) encoding for the function md

2020-02-15 05:08发布

When I tested this little script:

$str = "apple";

echo md5($str);

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

Should I trust that this will always be the case in any other environment?

If I where to put this script on any webhost, windows or linux, would it behave always the same with UTF8 encoding ?

2条回答
家丑人穷心不美
2楼-- · 2020-02-15 05:22

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

查看更多
何必那么认真
3楼-- · 2020-02-15 05:23

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.

查看更多
登录 后发表回答