crc32
Calculate a string of crc32 polynomials
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.
Output the result of crc32()
:
<?php $str = crc32 ( "Shanghai" ) ; printf ( "%u\n" , $str ) ; ?>
Try it yourself
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
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
crc32 ( string )
parameter | describe |
---|---|
string | Required. Specifies the string to be calculated. |