Content · Programming · PHP

PHP crc32() Function: Usage and Examples

Learn how PHP crc32 works with practical examples, important behavior, relevant alternatives and common mistakes.

1 views Published Oct 16, 2026 Updated Oct 16, 2026

Computes a 32-bit CRC checksum for detecting accidental changes.

What Is crc32() in PHP?

Computes a 32-bit CRC checksum for detecting accidental changes.

Its syntax is:

crc32(string $string): int

Parameters:

  • $string — Accepted as string; required argument.

Return type: int. CRC32 is not cryptographically secure. Use hash() or hash_hmac() where integrity must resist tampering.

Availability: Core PHP.

Example 1: Basic Usage

<?php

echo sprintf("%u", crc32("hello"));

Output:

907060870

CRC32 is not cryptographically secure. Use hash() or hash_hmac() where integrity must resist tampering.

Example 2: A Different Input

<?php

echo sprintf("%08x", crc32("data"));

Output:

adf3f363

CRC32 is not cryptographically secure. Use hash() or hash_hmac() where integrity must resist tampering.

Practical Example: Applying It in a Program

<?php

$payload = "order:42"; $checksum = sprintf("%08x", crc32($payload)); echo "Checksum: " . $checksum;

Output:

Checksum: 4e9eb32b

CRC32 is not cryptographically secure. Use hash() or hash_hmac() where integrity must resist tampering.

Important Behavior and Edge Cases

  • Key behavior: CRC32 is not cryptographically secure. Use hash() or hash_hmac() where integrity must resist tampering.
  • Environment: Core PHP.

Comparison With Related Functions

FunctionPurpose
crc32()Computes a 32-bit CRC checksum for detecting accidental changes.
hash()hash() supports named cryptographic digest algorithms; crc32() is a checksum, not a cryptographic hash.

Common Beginner Mistakes

MistakeCorrect Approach
Ignoring this behavior: CRC32 is not cryptographically secureCRC32 is not cryptographically secure. Use hash() or hash_hmac() where integrity must resist tampering.

Key Takeaways

  • Computes a 32-bit CRC checksum for detecting accidental changes.
  • CRC32 is not cryptographically secure. Use hash() or hash_hmac() where integrity must resist tampering.
  • Core PHP.

Summary: CRC32 is not cryptographically secure. Use hash() or hash_hmac() where integrity must resist tampering.

Share this resourceSend this page to someone who may find it useful.