How to Use md5() Function in PHP 8.1 and 8.2 with Example?

Support PHP Version: PHP 7.1, PHP 7.2, PHP 7.3, PHP 7.4, PHP 8.0, PHP 8.1, PHP 8.2, PHP 8.3 With Latest All Version Support.

In PHP 8.1 and 8.2, the `md5()` function remains available for generating MD5 hashes. Here’s how you can use it along with an example output:

<?php

// Define a string to hash
$string = "Hello, world!";

// Generate the MD5 hash
$hash = md5($string);

// Output the hash
echo "MD5 hash of '$string': $hash";

?>

This script will output something like:

MD5 hash of 'Hello, world!': b10a8db164e0754105b7a99be72e3fe5

The `md5()` function in PHP calculates the MD5 hash of a string. It takes the input string and returns a 32-character hexadecimal number. However, MD5 is considered to be a weak hashing algorithm and should not be used for cryptographic purposes like storing passwords securely. Instead, consider using stronger algorithms like `password_hash()` with bcrypt or Argon2 in PHP for such purposes.