← All languages
PHP function of the day
Random

md5

Calculate the MD5 hash of a string.

Description

The md5() function calculates the MD5 message digest of a string, returning a 32-character hexadecimal number. An optional parameter can make it return the raw 16-byte binary digest instead.

MD5 is no longer considered cryptographically secure for password hashing or digital signatures. For password hashing, use password_hash() with PASSWORD_BCRYPT or PASSWORD_ARGON2ID. For integrity verification, use hash() with SHA-256 or stronger.

Despite its cryptographic weaknesses, md5() remains widely used for checksums, cache busting, generating unique identifiers, and data fingerprinting where collision resistance is not critical.

Arguments

NameDescriptionOptional
string The string to hash. No
binary If true, returns raw 16-byte binary format. Defaults to false. Yes

Example

echo md5('Hello');           // "8b1a9953c4611296a827abf8c47804d7"
echo md5('Hello') === md5('Hello');  // true
echo md5('hello');           // "5d41402abc4b2a76b9719d911017c592"

Reference