PHP crc32() Function
Last Updated :
11 Jul, 2025
Improve
The crc32() function helps us to calculate a 32-bit crc or cyclic redundancy checksum polynomial for a string. The function uses the CRC32 algorithm.This function can be used to validate data integrity.
However, to ensure that we get the correct string representation from the crc32() function, we need to use the %u formatter of the printf() or sprintf() function. If the %u formatter is not used, the result may display incorrect and negative numbers.
Syntax:
PHP
Output:
PHP
Output:
PHP
Output:
crc32($string)Parameter:
- $string: This parameter specifies the string for which we want to find the crc32 polynomial.
Input : Hello world. Output : 2335835140 Input : Geeks For Geeks. Output : 2551101144Below programs illustrate the crc32() function. Program 1 : This program helps us to calculate a 32-bit CRC for the string "Hello World", both with %u and without %u.
<?php
// PHP program illustrate the
// crc32() function
$str1 = crc32("Hello world.");
// print without %u
echo 'Without %u: '.$str1."\n";
// print with %u
echo 'With %u: ';
printf("%u\n", $str1);
?>
Without %u: 2335835140 With %u: 2335835140Program 2 : This program helps us to calculate a 32-bit CRC for the string "GeeksforGeeks.", both with %u and without %u.
<?php
$str2 = crc32("GeeksforGeeks.");
// print without %u
echo 'Without %u: '.$str2."\n";
// print with %u
echo 'With %u: ';
printf("%u\n", $str2);
?>
Without %u: 3055367324 With %u: 3055367324Program 3 : This program helps us to calculate a 32-bit CRC for the string "Computer Science.", both with %u and without %u.
<?php
$str3 = crc32("Computer Science.");
// print without %u
echo 'Without %u: '.$str3."\n";
// print with %u
echo 'With %u: ';
printf("%u\n", $str3);
?>
Without %u: 3212073516 With %u: 3212073516Reference: https://www.php.net/manual/en/function.crc32.php