Current Location: Home> Function Categories> crc32

crc32

Calculate a string of crc32 polynomials
Name:crc32
Category:String
Programming Language:php
One-line Description:Calculates the 32-bit CRC of the string.

Definition and usage

crc32() function calculates the 32-bit CRC (cyclic redundancy check) of the string.

This function can be used to verify data integrity.

Tip: To ensure you get the correct string representation from the crc32() function, you need to use %u formatter of printf() or sprintf() function. If %u format is not used, the result may appear as incorrect numbers or negative numbers.

Example

Example 1

Output the result of crc32() :

 <?php
$str = crc32 ( "Shanghai" ) ;
printf ( "%u\n" , $str ) ;
?>

Try it yourself

Example 2

In this example, we will output the result of crc32() with and without the " %u " format (note that the result is the same):

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

Output of the above code:

 Without %u: 461707669
With %u: 461707669

Example 3

In this example, we will output the result of crc32() with and without the " %u " format (note that the results are different):

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

Output of the above code:

 Without %u: -1959132156
With %u: 2335835140

grammar

 crc32 ( string )
parameter describe
string Required. Specifies the string to be calculated.
Similar Functions
Popular Articles