一:int crc32 ( string str )
CRC的全称是循环冗余校验
生成 str 的 32 位循环冗余校验码多项式。这通常用于检查传输的数据是否完整。
由于 PHP 的整数是带符号的,许多 crc32 校验码将返回负整数,因此你需要使用 sprintf() 或 printf() 的“%u”格式符来获取表示无符号 crc32 校验码的字符串。
<?php$str = crc32("Hello world.");
echo 'Without %u: '.$str."<br />";
echo 'With %u: ';
printf("%u",$str);?>
输出:
Without %u: -1959132156With %u: 2335835140
二:string md5 ( string str [, bool raw_output] )
Calculates the MD5 hash of str using the RSA Data Security, Inc. MD5 Message-Digest Algorithm, and returns that hash. The hash is a 32-character hexadecimal number.
If the optional raw_output is set to TRUE, then the md5 digest is instead returned in raw binary format with a length of 16.
注: The optional raw_output parameter was added in PHP 5.0.0 and defaults to FALSE
md5() 函数计算字符串的 MD5 散列。
md5() 函数使用 RSA 数据安全,包括 MD5 报文摘译算法。
如果成功,则返回所计算的 MD5 散列,如果失败,则返回 false。
TRUE - 原始 16 字符二进制格式
FALSE - 默认。32 字符十六进制数
<?php
$str = 'apple';
if (md5($str) === '1f3870be274f6c49b3e31a0c6728957f') {
echo "Would you like a green or red apple?";
exit;
}
?>
三:string sha1 ( string str [, bool raw_output] )
Calculates the sha1 hash of str using the US Secure Hash Algorithm 1, and returns that hash. The hash is a 40-character hexadecimal number. If the optional raw_output is set to TRUE, then the sha1 digest is instead returned in raw binary format with a length of 20.
注: The optional raw_output parameter was added in PHP 5.0.0 and defaults to FALSE
sha1() 函数计算字符串的 SHA-1 散列。
sha1() 函数使用美国 Secure Hash 算法 1。
如果成功,则返回所计算的 SHA-1 散列,如果失败,则返回 false。
TRUE - 原始 20 字符二进制格式
FALSE - 默认。40 字符十六进制数
<?php
$str = 'apple';
if (sha1($str) === 'd0be2dc421be4fcd0172e5afceea3970e2f3d940') {
echo "Would you like a green or red apple?";
exit;
}
?>