Home >>PHP String Functions >PHP md5() Function
PHP md5() function is used to convert a given input string into MD5 hash. MD5 uses the Message-Digest algo for calculating the hash. The hash is returned as a 32 charcter hexadecimal number. This function is mostly used in the encryption of the password for the security. It accepts two parameters out of which one is required and the other one is optional.
Syntax:-
string md5($string, $RawOutput);
Parameter | Description |
---|---|
String | This is a required parameter. This parameter contains the string to be calculated. |
RawOutput | This is an optional parameter. This parameter specifies the hex or binary output format. It is of Boolean type.
|
Here is an example of md5() function in PHP:
<html> <body> <?php $str = "PHPTPOINT"; echo md5($str); ?> </body> </html>
Here is an another example of md5() function in PHP:
<html> <body> <?php $str = "PHPTPOINT"; echo "Input string: ".$str."<br>"; echo "Raw 16 character binary format: ".md5($str, TRUE)."<br>"; echo "32 character hex format: ".md5($str)."<br>"; ?> </body> </html>
Here is an another example of md5() function in PHP for the password security:
<html> <body> <?php $str = "Password"; echo md5($str); if (md5($str) == "dc647eb65e6711e155375218212b3964") { echo "<br><br>Password Matched !!"; exit; } ?> </body> </html>