Home >>PHP String Functions >PHP sha1() Function
PHP sha1() function is used to calculate the SHA-1 hash of a given input string. This PHP function uses the US Secure Hash Algorithm 1. It produces a 160-bit output called message digest. SHA stands for “Secure Hash Algorithm”.
Syntax:
sha1($string, $raw);
Parameter | Description |
---|---|
string | This is a required parameter. This parameter contains the string to be calculated. |
raw | This is an optional parameter. This parameter defines hex or binary output format:
|
Here is an example of sha1() function in PHP:
<html> <body> <?php $str = "PHPTPOINT"; echo sha1($str); ?> </body> </html>
Here is an another example of sha1() function in PHP:
<html> <body> <?php $str = "PHPTPOINT"; echo "Original string: ".$str."<br><br>"; echo "TRUE - 20 character binary format: ".sha1($str, TRUE)."<br><br>"; echo "FALSE - 40 character hex number: ".sha1($str)."<br>"; ?> </body> </html>