md5() Function in PHP 8.5

The md5() function in PHP 8.5 remains unchanged from previous versions. It calculates the MD5 hash of a string using the RSA Data Security, Inc. MD5 Message-Digest Algorithm.

Function Signature

md5(string $string, bool $binary = false): string

Parameters

→$string: The string to be hashed.
→$binary (optional): If set to true, the function returns the raw binary format (16 bytes). By default, it returns a 32-character hexadecimal number.

Example

<?php
$str = apple ;

// Default: returns 32-character hex string
$hash_hex = md5($str);
echo $hash_hex; 
// Output: 1f3870be274f6c49b3e31a0c6728957f

// Raw binary output (16 bytes)
$hash_raw = md5($str, true);
echo bin2hex($hash_raw); 
// Output: 1f3870be274f6c49b3e31a0c6728957f (same value, just binary format)
?>

4 Views