md5 – PHP String Functions

Syntax :

md5 ( string, raw_output );

Description :

The md5() function calculates the MD5 hash of a string.

The md5() function uses the RSA Data Security, Inc. MD5 Message-Digest Algorithm and returns that hash.

Use the md5_file() function to calculate the MD5 hash of a file.


Parameter :

[table caption=”” width=”100%” colwidth=”15%|15%|15%|55%” colalign=”left|lef|lef|left”]
Name, Required /Optional, Value Type, Description

string , Required, String , It is the string for which we have to get MD5 hash.

Raw_output, Optional, Boolean, When TRUE it returns the digest in raw binary format with 16 characters length. By default its FALSE returns 32 characters hex number.
[/table]


Output :

This will returns a MD5 hash of a string on success, otherwise FALSE.


Related articles :  sha1_file(), crc32(), md5_file(), sha1() , hash() , crypt() , password_hash() .


md5_​file() – PHP Functions Example 1 :
<?php
$strExample = 'mango';
echo md5($strExample).'\n';
if (md5($strExample) === 'aa00faf97d042c13a59da4d27eb32358') {
    echo "Would you like a green or yellow mango?";
}
?>

See below is the output of above code in Web browser.

aa00faf97d042c13a59da4d27eb32358
Would you like a green or yellow mango?

md5_​file() – PHP Functions Example 2 : Using both values in Raw_output parameter i.e TRUE, FALSE by DEFAULT
<?php 
$strExample = "Tutorialmines.net"; 
echo "The string is : ".$strExample."<br>"; 
echo "TRUE - Raw 16 character binary format: ".md5($strExample, TRUE)."<br>"; 
echo "FALSE - 32 character hex number: ".md5($strExample)."<br>"; 
?>

See below is the output of above code in Web browser.

The string is : Tutorialmines.net
TRUE – Raw 16 character binary format: ���c�b���1r9ǿ�
FALSE – 32 character hex number: 0df9c1c8638e6280b9e3317239c7bfe3

You may also like...