PHP md5 hash function

PHP md5 hash function is used to create a hash from given string. And generated has will be 32 characters long, even if the sting is more than that length. This md5 function will takes two arguments but we need to pass only one argument that is string. Then after that it will generates a md5 hash string which is 32 characters long. The md5() function calculates the MD5 hash of a string.

Syntax for php md5 hash function


Simple code for using php md5 hash function

$str = "apple";
echo md5($str);

and one more example of comparing string with md5 hash

$str = 'apple';

if (md5($str) === '1f3870be274f6c49b3e31a0c6728957f') {
    echo "Would you like a green or red apple?";

After executing this code you will get md5 hash for that string. And the string generated by md5 hash will be used to store password in database, instead of saving plain text password in database if you save hashed string of that text, then user information will be secure.

Note: It is not recommended to use this function to secure passwords.

Vivek Vengala

Vivek Vengala is a Online Entrepreneur, Web Developer from Hyderabad India.

Click Here to Leave a Comment Below 0 comments

Leave a Reply: