PHP crc32() function
Example
Output the result of crc32():
<?php $str = crc32("Shanghai"); printf("睵n",$str); ?>
Definition and Usage
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 the correct string representation is obtained from the crc32() function, you need to use the ꊻmat specifier of the printf() or sprintf() function. If the ꊻmat specifier is not used, the result may be displayed as an incorrect number or a negative number.
Syntax
crc32(string)
Parameter | Description |
---|---|
string | Required. Specifies the string to be calculated. |
Technical Details
Return Value: | Returns the 32-bit CRC (cyclic redundancy check) polynomial of a string as an integer. |
PHP Version: | 4.0.1+ |
Example 1
In this example, we will output the result of crc32() with and without using the "眻 format specifier (note that the results are the same):
<?php $str = crc32("Hello world!"); echo 'Without ៷$str."<br>"; echo 'With ᠄ printf("眻,$str); ?>
The output of the above code is:
Without ᥆1707669 With ᥆1707669
Example 2
In this example, we will output the result of crc32() with and without using the "眻 format specifier (note that the results are different):
<?php $str = crc32("Hello world."); echo 'Without ៷$str."<br>"; echo 'With ᠄ printf("眻,$str); ?>
The output of the above code is:
Without ᡡ959132156 With ᤣ35835140