超越PHP PHP动态 | 经典文章 | CLASS | 相关下载 | 常见问题 | FORUM | WIKI | 在线手册
Site search:    
<count_charscrypt>
Last updated: Fri, 22 Jun 2007

crc32

(PHP 4 >= 4.0.1, PHP 5)

crc32 -- 计算一个字符串的 crc32 多项式

描述

int crc32 ( string str)

生成 str 的 32 位循环冗余校验码多项式。这通常用于检查传输的数据是否完整。

由于 PHP 的整数是带符号的,许多 crc32 校验码将返回负整数,因此你需要使用 sprintf()printf() 的“%u”格式符来获取表示无符号 crc32 校验码的字符串。

示例中的第二行演示了如何使用 printf() 函数转换校验码:

例子 1. 显示 crc32 校验码

<?php
$checksum
= crc32("The quick brown fox jumped over the lazy dog.");
printf("%u\n", $checksum);
?>

参见 md5()sha1()




add a note add a note User Contributed Notes
crc32
spectrumizer at cycos dot net
30-Dec-2002 07:30
Here is a tested and working CRC16-Algorithm:

<?php
function crc16($string) {
 $crc = 0xFFFF;
 for ($x = 0; $x < strlen ($string); $x++) {
   $crc = $crc ^ ord($string[$x]);
   for ($y = 0; $y < 8; $y++) {
    if (($crc & 0x0001) == 0x0001) {
       $crc = (($crc >> 1) ^ 0xA001);
     } else { $crc = $crc >> 1; }
   }
}
 return $crc;
}
?>

Regards,
Mario

<count_charscrypt>
 Last updated: Fri, 22 Jun 2007
view source | feedback | send page | sitemap | aboutus   
Copyright ® 2002-2003 PHPE.NET. All rights reserved
Last updated:2002-11-22