Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP crc32() Function

PHP crc32() Function

PHP String Reference Manual PHP String Reference Manual

Example

Output the result of crc32():

Run Example »


Definition and Usage

The crc32() function calculates a 32-bit CRC (Cyclic Redundancy Check) of a string.

This function can be used to verify data integrity.

**Tip:** To ensure you get the correct string representation from the crc32() function, you must use the %u format specifier of printf() or sprintf(). If the %u format specifier is not used, the result may appear as an incorrect number or a negative number.


Syntax

crc32(

string

)

Parameters Description
string Required. Specifies the string to calculate.

Technical Details

Return Value: Returns, as an integer, the string 32-bit CRC polynomial.
PHP Version: 4.0.1+

Example 1

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

Example

" ; echo ' With %u: ' ; printf ( " %u " , $str ) ; ?>

The code above will output:

Without %u: 461707669
With %u: 461707669

Example 2

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

Example

" ; echo ' With %u: ' ; printf ( " %u " , $str ) ; ?>

The code above will output:

Without %u: -1959132156
With %u: 2335835140

PHP String Reference Manual PHP String Reference Manual