PHP sha1() Function
In this chapter you will learn:
- Definition for PHP sha1() Function
- Syntax for PHP sha1() Function
- Parameter for PHP sha1() Function
- Return for PHP sha1() Function
- Example - GEt the SHA1 hash value for strings
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//j av a 2 s . c om
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.
Next chapter...
What you will learn in the next chapter:
- Definition for PHP similar_text() Function
- Syntax for PHP similar_text() Function
- Parameter for PHP similar_text() Function
- Return for PHP similar_text() Function
- Example - Calculate the similarity between two strings and return the matching characters
- Example - Calculate the similarity between two strings in percent
Home » PHP Tutorial » PHP String Functions