Showing posts with label PHP crc32. Show all posts
Showing posts with label PHP crc32. Show all posts

Thursday, 25 September 2014

crc32 in PHP

PHP crc32() function is utilized to generate 32-bit Cyclic Redundancy Checksum (CRC) for a string.
PHP crc32() is usually used to validate the integrity of data being transmitted.

Syntax:

crc32(string)
 
Parameter Description: 
string : Required. The input string.
Tip :  many crc32 checksums will bring about negative integers, you need to utilize the "%u" formatter of sprintf() or printf() to get the string representation of the unsigned crc32 checksum.

Example:

<?php 
echo "<strong>here we will print the result of crc32() with and without the (%u) formatter :</strong><br />";
$str_name = crc32("Good Morning!");
echo 'Without %u : '. $str_name."<br />"; 
echo 'With %u : ';
printf("%u",$str_name);
?>

O/P:

here we will print the result of crc32() with and without the (%u) formatter : 

Without %u : -1046389996 

With %u : 3248577300