PHP: md5() function


The md5() function is used to calculate the md5 hash (the hash as a 32-character hexadecimal number ) of a string.


(PHP 4 and above)


md5(input_string, raw_output)


Name Description Required /
input_string The input string. Required Float
raw_output Refers hex or binary output format, Returns raw 16-bit binary format if raw_output sets TRUE and return 32-bit hex format for setting FALSE (default). Optional Boolean

Return value:

Returns the hash as a 32-character hexadecimal number.

Value Type: String.

Pictorial Presentation



$input_string = 'Good Morning';
echo 'Original string : '.$input_string.'<br>';
echo '16 bit binary format : '.md5($input_string, TRUE).'<br>';
echo '32 bit binary format : '.md5($input_string).'<br>';


Original string : Good Morning
16 bit binary format : r y†”	  du?Û£¿ân
32 bit binary format : 72a079088694099d64753fdba3bfe26e

View the example in the browser

See also

PHP Function Reference

Previous: md5_file
Next: metaphone

PHP: Tips of the Day

In PHP, there are two versions of logical AND and OR operators.

Operator True if
$a and $b Both $a and $b are true
$a && $b Both $a and $b are true
$a or $b Either $a or $b is true
$a || $b Either $a or $b is true

Note that the && and || opererators have higher precedence than and and or. See table below:

Evaluation Result of $e Evaluated as
$e = false || true True $e = (false || true)
$e = false or true False ($e = false) or true

Because of this it's safer to use && and || instead of and and or.