Output the results of crc32():
<?php$str = crc32("Hello World!");printf("%un",$str);?>The crc32() function calculates the 32-bit CRC (cyclic redundancy check) of a string.
This function can be used to verify data integrity.
Tip: To ensure that you get the correct string representation from the crc32() function, you must use the %u format character of the printf() or sprintf() function. If the %u format character is not used, the results may appear as incorrect numbers or negative numbers.
crc32( string )
parameter | describe |
---|---|
string | Required. Specifies the string to be calculated. |
Return value: | Returns the 32-bit cyclic redundancy check code polynomial of string as an integer. |
---|---|
PHP version: | 4.0.1+ |
In this example, we will output the results of crc32() with and without the "%u" formatter (note that the results are the same):
<?php$str = crc32("Hello world!");echo 'Without %u: '.$str."<br>";echo 'With %u: ';printf("%u",$str) ;?>
The above code will output:
Without %u: 461707669With %u: 461707669
In this example, we will output the results of crc32() with and without the "%u" formatter (note that the results are different):
<?php$str = crc32("Hello world.");echo 'Without %u: '.$str."<br>";echo 'With %u: ';printf("%u",$str) ;?>
The above code will output:
Without %u: -1959132156With %u: 2335835140