Latest web development tutorials

PHP crc32 () function

PHP String Reference PHP String Reference

Examples

Output crc32 () result:

<?php
$str = crc32("Hello World!");
printf("%un",$str);
?>

Running instance »

Definition and Usage

crc32 () function calculates a string of 32-bit CRC (cyclic redundancy check).

This function can be used to verify data integrity.

Tip: To make sure you from crc32 () function to obtain the correct string representation, you must use the printf () or sprintf () function% u format character.If you do not use the% u format character, the results may appear to be incorrect or negative numbers.


grammar

crc32( string )

参数 描述
string 必需。规定要计算的字符串。

technical details

return value: Returned as an integer string of 32-bit cyclic redundancy check code polynomial.
PHP version: 4.0.1+


Example 1

In this example, we will use and without the use of "% u" formatter, the output crc32 () results (Note that the results are the same):

<?php
$str = crc32("Hello world!");
echo 'Without %u: '.$str."<br>";
echo 'With %u: ';
printf("%u",$str);
?>

The code above will output:

Without %u: 461707669
With %u: 461707669


Example 2

In this example, we will use and without the use of "% u" formatter, the output crc32 () results (Note that the results are not the same):

<?php
$str = crc32("Hello world.");
echo 'Without %u: '.$str."<br>";
echo 'With %u: ';
printf("%u",$str);
?>

The code above will output:

Without %u: -1959132156
With %u: 2335835140


PHP String Reference PHP String Reference