md5()
md5() — Calculate the md5 hash of a string.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
Calculates the MD5 hash of string using the RSA Data Security, Inc. MD5 Message-Digest Algorithm, and returns that hash.
Signature
md5(string $string, bool $binary = false): string
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $string | string | The string. |
| $binary | bool | If the optional binary is set to true, then the md5 digest is instead returned in raw binary format with a length of 16. |
Return value
Returns the hash as a 32-character hexadecimal number.
Example
A runnable snippet:
$str = 'apple'; if (md5($str) === '1f3870be274f6c49b3e31a0c6728957f') { echo "Would you like a green or red apple?"; }
See also
All PHP 8.5 built-in functions
Reference card built from the PHP manual page md5() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.