Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

php
encryption
communitycreator

What is the md5 function in PHP?

Dario Vincenzo Tarantini

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The md5 function in PHP computes the md5 hash of a string.

md5 should not be used to encrypt passwords because it is a high-speed algorithm and can easily be brute-forced to reveal the original input.

Syntax

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

Parameters

  • $str: the string you want to hash.
  • $binary: a Boolean to specify if the result should be in raw binary form (if set to True) or a hexadecimal number (if set to False). The default value is False.

Return value

It returns a hash value of the string in the form as specified by $binary.

Code

This simple example will compute the md5 hash of a string:

<?php
$myhash = md5("Hello, educative!");
echo "Hash: " . $myhash;

RELATED TAGS

php
encryption
communitycreator

CONTRIBUTOR

Dario Vincenzo Tarantini

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring