PHP sha1() Function

Definition

SHA converts a string into a hash value in 40-bit hexadecimal number. Checksums are one-way encryption to check the accuracy of input.

SHA stands for the "Secure Hash Algorithm,".

Syntax

PHP sha1() Function has the following syntax.

string sha1 ( string str [, bool raw_output] )

Parameter

If the optional second parameter is true, the SHA1 checksum is in raw binary format whose length is 20.

Return

PHP sha1() Function returns the SHA1 hash value for a string.

Example


<?PHP/*from ww w. j  a  v a 2 s .c  o  m*/
print sha1("hello") . "\n"; 
print sha1("Hello") . "\n"; 
print sha1("hello") . "\n"; 
print sha1("This is from java2s.com"); 
?>

sha1() will always give the same output for a given input.

The code above generates the following result.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions