PHP中函数md5()的(默认)编码是什么? [英] What is the (default) encoding for the function md5() in PHP?

查看:612
本文介绍了PHP中函数md5()的(默认)编码是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我测试了这个小脚本:

When I tested this little script:

$str = "apple";

echo md5($str);

结果与使用utf8(使用C#测试)进行md5的结果相匹配

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?

如果我将这个脚本放在任何webhost上, windows或linux,它的行为总是与 UTF8 编码一样吗?

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

推荐答案

p>字符串文字的编码是保存源文件的任何编码。如果您以UTF-16保存了这个php文件,您将得到不同的结果,即代码甚至运行。

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.

PHP中没有统一的或受管理的编码。 PHP中的字符串可以是任何编码,换句话说,它们相当于具有更多抽象字符串类型的语言的字节数组。

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.

这篇关于PHP中函数md5()的(默认)编码是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆