PHP String function
Instance
Computes the MD5 hash of the string "Hello":
<?php
$str = "Shanghai";
echo md5($str);
?>
Running an instance
Definition and usage
The MD5 () function computes the MD5 hash of the string.
The MD5 () function uses RSA data security, including MD5 Digest to algorithm.
Explanation from RFC 1321-MD5 Digest to algorithm: MD5 Digest to the algorithm will be arbitrary length of information as input value, and convert it into a 128-bit length of "fingerprint Information" or "Digest to" value to represent this input value, and with the converted value as the result. The MD5 algorithm is designed primarily for digitally signed applications, where large files are compressed in a secure manner prior to encryption (where encryption is done by setting a private key under the public key of a cryptographic system, such as RSA).
To calculate the MD5 hash of a file, use the Md5_file () function.
Grammar
MD5 (string,raw)
Parameters |
Description |
String |
Necessary. Specifies the string to be computed. |
Raw |
Optional. Specify hexadecimal or binary output formats:
- TRUE-Original 16 character binary format
- FALSE-Default. 32-character hexadecimal number
|
Technical details
return value: |
Returns the computed MD5 hash if successful, or FALSE if it fails. |
PHP version: |
4 + |
Update log: |
In PHP 5.0, theraw parameter becomes optional. |
More examples of examples 1
Results of output MD5 ():
<?php
$str = "Shanghai";
Echo "string:".$str."<br>";
Echo "TRUE - original 16 character binary format: ".md5($str, TRUE)."<br>";
Echo "FALSE - 32 characters in hexadecimal format: ".md5($str)."<br>";
?>
Running an instance
Example 2
Output the result of MD5 () and test it:
<?php
$str = "Shanghai";
echo md5($str);
if (md5($str) == "5466ee572bcbc75830d044e66ab429bc")
{
echo "<br>Hello world!";
exit;
}
?>
PHP MD5 () function