w3resource

PHP: md5() function

Description

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

Version:

(PHP 4 and above)

Syntax:

md5(input_string, raw_output)

Parameter:

Name Description Required /
Optional
Type
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

php-string-md5()

Example:

<?php
$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>';
?>

Output:

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

PHP: Pass a PHP string to a JavaScript variable (and escape newlines)

<script>
  var myvar = <?php echo json_encode($myVarValue); ?>;
</script>

Using json_encode() requires:

  • PHP 5.2.0 or greater
  • $myVarValue encoded as UTF-8 (or US-ASCII, of course)

Since UTF-8 supports full Unicode, it should be safe to convert on the fly.

Note that because json_encode escapes forward slashes, even a string that contains </script> will be escaped safely for printing with a script block.

Ref : https://bit.ly/34f0Dym