Computer >> Computer tutorials >  >> Programming >> PHP

crc32() function in PHP


The crc32() function is used to calculate 32-bit CRC. You can use the function to validate data integrity.

Syntax

crc32(str)

Parameters

  • str  − The string

Return

The crc32() function returns the crc32 checksum of string as an integer.

Example

The following is an example −

<?php
   $res = crc32("This is demo text!");
   printf("%u\n", $res);
?>

Output

2903462745

Example

Let us see another example −

<?php
   $s = crc32("Welcome!");
   echo 'First:'.$s."\n";
   printf("Second: %u\n", $s);
?>

Output

First: 893564114 Second: 893564114