(PHP 4 >= 4.0.1, PHP 5, PHP 7)
crc32 — ����һ���ַ����� crc32 ����ʽ
$str
) : int
���� str
�� 32 λѭ������У�������ʽ����ͨ�����ڼ�鴫��������Ƿ�������
���� PHP �������Ǵ����ŵģ������� 32 λϵͳ����� crc32 У���뽫���ظ������� ������ 64 λ������ crc32() �Ľ����������������
�������Ҫʹ�� sprintf() �� printf() ��"%u"��ʽ������ȡ��ʾ���� crc32 У������ַ�����
For a hexadecimal representation of the checksum you can either use the "%x" formatter of sprintf() or printf() or the dechex() conversion functions, both of these also take care of converting the crc32() result to an unsigned integer.
Having 64bit installations also return negative integers for higher result values was considered but would break the hexadecimal conversion as negatives would get an extra 0xFFFFFFFF######## offset then. As hexadecimal representation seems to be the most common use case we decided to not break this even if it breaks direct decimal comparisons in about 50% of the cases when moving from 32 to 64bits.
In retrospect having the function return an integer maybe wasn't the best idea and returning a hex string representation right away (as e.g. md5() does) might have been a better plan to begin with.
For a more portable solution you may also consider the generic
hash(). hash("crc32b", $str)
will
return the same string as dechex(crc32($str))
.
str
ҪУ������ݡ�
���� str
crc32 ���������
Example #1 ��ʾһ�� crc32 У����
ʾ���еĵڶ�����ʾ�����ʹ�� printf() ����ת��У���룺
<?php
$checksum = crc32("The quick brown fox jumped over the lazy dog.");
printf("%u\n", $checksum);
?>