PHP Tutorial - PHP sha1() Function


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,".


PHP sha1() Function has the following syntax.

string sha1 ( string str [, bool raw_output] )


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


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


print sha1("hello") . "\n"; 
print sha1("Hello") . "\n"; 
print sha1("hello") . "\n"; 
print sha1("This is from"); 

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

The code above generates the following result.