Instance
Results of output CRC32 ():
<?php$str = CRC32 ("Hello world!"); printf ("%un", $str);? >
Definition and usage
The CRC32 () function computes a 32-bit CRC (cyclic redundancy check) for a string.
This function can be used to verify the integrity of the data.
Tip: To ensure that you can get the correct string representation from the CRC32 () function, you must use the%u format of the printf () or sprintf () function. If you do not use the%u format, the results may appear as incorrect numbers or negative values.
Grammar
CRC32 (String)
Parameter description
string is required. Specifies the string to be computed.
Technical details
Return value: A 32-bit cyclic redundancy check code polynomial that returns a string as an integer.
PHP version: 4.0.1+
Example 1
In this example, we will output the results of the CRC32 () (note the same result) in the case of using and not using the "%u" format character:
<?php$str = CRC32 ("Hello world!"); Echo ' without%u: '. $str. " <br> "; Echo ' with%u: ';p rintf ("%u ", $str);? >
The above code will output:
Without%u:461707669with%u:461707669
Example 2
In this example, we will output the results of CRC32 () without using the "%u" format character (note the result is not the same):
<?php$str = CRC32 ("Hello World"); Echo ' without%u: '. $str. " <br> "; Echo ' with%u: ';p rintf ("%u ", $str);? >
The above code will output:
Without%u: -1959132156with%u:2335835140
The result returned by CRC32 will overflow on a 32-bit machine, so the result may be negative. The 64-bit machine does not overflow, so it is always positive.
The CRC algorithm is calculated by bit-length bits.
The CRC32 function is calculated as a reference to the two constants in PHP Php_int_size,php_int_max
The definitions of these two constants:
The word length of an integer is related to the platform, although the usual maximum value is approximately 2 billion (32-bit signed). PHP does not support unsigned integers. The length of the integer value can be expressed as a constant php_int_size, since PHP 4.4.0 and PHP 5.0.5, the maximum value can be expressed as a constant php_int_max.
Output under 32 bits in php_int_size:4,php_int_max:2147483647
Output under 64 bits in php_int_size:8,php_int_max:9223372036854775807