PHP crc32() 函数

实例

输出 crc32() 的结果:

<?php
$str = crc32("Shanghai");
printf("睵n",$str);
?>

运行实例

定义和用法

crc32() 函数计算字符串的 32 位 CRC(循环冗余校验)。

该函数可用于验证数据完整性。

提示:为了确保从 crc32() 函数中获得正确的字符串表示,您需要使用 printf() 或 sprintf() 函数的 ﵯ。如果未使用 ﵯ,结果可能会显示为不正确的数字或者负数。

语法

crc32(string)
参数 描述
string 必需。规定要计算的字符串。

技术细节

返回值: 以整数值返回字符串的 32 位循环冗余校验码多项式。
PHP 版本: 4.0.1+

例子 1

在本实例中,我们将在使用以及不使用 "眻 格式符的情况下,输出 crc32() 的结果(注意结果是相同的):

<?php
$str = crc32("Hello world!");
echo 'Without ៷$str."<br>";
echo 'With ᠄
printf("眻,$str);
?>

以上代码的输出:

Without ᥆1707669
With ᥆1707669

例子 2

在本实例中,我们将在使用以及不使用 "眻 格式符的情况下,输出 crc32() 的结果(注意结果是不相同的):

<?php
$str = crc32("Hello world.");
echo 'Without ៷$str."<br>";
echo 'With ᠄
printf("眻,$str);
?>

以上代码的输出:

Without ᡡ959132156
With ᤣ35835140