PHP Function Reference

PHP crc32() Function



The PHP crc32() function generates the cyclic redundancy checksum polynomial of 32-bit lengths of the string. This is usually used to validate the integrity of data being transmitted.

Note: As PHP's integer type is signed, therefore many crc32() checksums will result in negative integers on 32bit platforms. On 64bit installations all crc32() results will be positive integers though.

The %u formatter of the printf() or sprintf() function should be used to get the correct string representation of the unsigned crc32() checksum in decimal format. If the %u formatter is not used, the result may display in incorrect and negative numbers.

For a hexadecimal representation of the checksum, the "%x" formatter of sprintf() or printf() or the dechex() conversion functions can be used.

Syntax

crc32(str)

Parameters

str Required. Specify the string to be calculated.

Return Value

Returns the crc32 checksum of string as an integer.

Example: crc32() example

In the example below shows the usage of crc32() function.

<?php
$str = "Hello World!";
$checksum = crc32($str);
printf("%u",$checksum);
?>

The output of the above code will be:

472456355

❮ PHP String Reference