PHP crc32() Function

PHP count_chars() Function
PHP crypt() Function

In this article, you will learn how to validate the integrity of the data. You must know about the term validity of integrity of the data. Integrity makes sure that a particular data is a private property of someone and the PHP CRC32() function validates this integrity.

The basic functionality of the CRC32() function is to calculate a 32-bit cyclic redundancy checksum for the given string which is used for the validation purposes.

Note: To get the correct output of the crc32() function, you must use formatter %u with the printf() or sprintf() function. If these formatters are not used, you may get incorrect or negative numbers in the output.

What is the syntax of the CRC32() function in php?

crc32(string)
ParameterDescription
stringRequired. The string to be calculated
PHP CRC32() function

Examples of the CRC32() function

Example 1. In this example, we use the crc32() function and return its output using the formatter %u.

<?php
$str = crc32("Hello PHP!");
printf("%u\n",$str);
?>

Example 2. In this example, we use the crc32() function and return its output using and without using the formatter %u. The results will be same in both cases.

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

Example 3. In this example, we use the crc32() function and return its output using and without using the formatter %u. The results will not be same in both cases.

<?php
$str = crc32("Hello PHP.");
echo 'Without using formatter %u: '.$str."<br>";
echo 'Using formatter %u: ';
printf("%u",$str);
?>
PHP count_chars() Function
PHP crypt() Function

Stay up-to-date about PHP!

We don’t spam!

en English
X
Scroll to Top