当前位置: 首页 > 网络学院 > 服务端脚本教程 > PHP > crc32() 函数

PHP
PHP 介绍
PHP 安装
PHP 语法
PHP 变量
PHP操作符
PHP If...Else
PHP Switch
PHP 数组
PHP 循环
PHP 函数
PHP 表单
PHP $_GET
PHP $_POST
PHP Date
PHP Include
PHP 文件处理
PHP 文件上传
PHP Cookies
PHP Sessions
PHP 发送邮件

PHP 中的 crc32() 函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 584 ::
收藏到网摘: n/a

Definition and Usage
定义和用法

The crc32() function calculates a 32-bit CRC (cyclic redundancy checksum) for a string.
crc32()函数的作用是:计算一个字符串的 crc32 多项式。

This function can be used to validate data integrity.
这个函数使用来验证一个整数的有效性的。

Syntax
案例

crc32(string)

Parameter参数 Description描述
string Required. The string to be calculated
必要参数。选择需要计算的字符串


Tips and Notes
提示

Tip: To ensure that you get the correct string representation from the crc32() function, you'll need to use the %u formatter of the printf() or sprintf() function. If the %u formatter is not used, the result may display in incorrect and negative numbers.
提示:为了确保使用crc32()函数来获取正确的字符串陈述,你将使用printf()函数或sprintf()函数%u格式;如果不使用%u格式,结果可能将不会正确显示或以一个负数显示。


Example 1
案例1

In this example we will print the result of crc32() with and without the "%u" formatter (note that the result is equal):
在下面这个案例中,我们将使用/不使用“%u”格式来输出crc32()的结果(注意:返回的结果是相同的):

<?php
$str = crc32("Hello world!");
echo 'Without %u: '.$str."<br />";
echo 'With %u: ';
printf("%u",$str);
?> 

The output of the code above will be:
上述代码将输出下面的结果:

Without %u: 461707669
With %u: 461707669


Example 2
案例2

In this example we will print the result of crc32() with and without the "%u" formatter (note that the result is not equal):
在下面这个案例中,我们将使用/不使用“%u”格式来输出crc32()的结果(注意:返回的结果是不相同的):

<?php
$str = crc32("Hello world.");
echo 'Without %u: '.$str."<br />";
echo 'With %u: ';
printf("%u",$str);
?> 

The output of the code above will be:
上述代码将输出下面的结果:

Without %u: -1959132156
With %u: 2335835140

评论 (0) All

登陆 | 还没注册?