Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

md5

Returns the MD5 hash of a string.

Syntax

md5(string $string): string

Parameters

ParameterTypeDescription
$stringstringThe source string.

Return value

stringA hash of 32 hexadecimal characters.

Examples

The hash of a string:

<?php
 
echo md5('hello');

Output:

5d41402abc4b2a76b9719d911017c592

The same content gives the same hash:

<?php
 
var_dump(md5('text') === md5('text'));
var_dump(md5('text') === md5('Text'));

Output:

bool(true)
bool(false)

Notes

MD5 suits cache keys and checking whether a file changed. It is unfit for passwords — use password_hash().

See also

  • hash — Returns the hash of a string using a chosen algorithm.
  • password_hash — Creates a password hash for storing in a database.

In the tutorial

  • Security — The basics of PHP site security — XSS and escaping, SQL injection, password hashing, CSRF tokens and validating input.

Thanks for reading!

Donate to the site — we work hard for you.