sha1 – PHP String Functions
Syntax :
Description :
sha1() function calculates the sha1 hash of a string.
Parameter :
[table caption=”” width=”100%” colwidth=”15%|15%|15%|55%” colalign=”left|lef|lef|left”]
Name, Required /Optional, Value Type, Description
string , Required, String , The file for which hash is to be calculated.
raw_output, Optional, boolen, A boolean value that specifies hex or binary output format:
,,If TRUE, Raw 20 character binary format data will be returned.
,,If FALSE, Default 40 character hex number will be returned.
[/table]
Output :
This function returns the string, calculated for SHA-1 hash as a string.
ChangeLog :
[table caption=”” width=”100%” colwidth=”25%|75%” colalign=”left|left”]
Version, Description
PHP 5.1.0 , Changed the function to use the streams API. It means that you can use it with wrappers like sha1_file(‘http://www.tutorialmines.net/..’)
[/table]
Related articles : md5(), sha1_file(), crc32(), md5_file(), crypt().
sha1() – PHP Functions Example 1 :
<?php
$strExample = 'tutorialmines.net';
echo "\n".sha1($strExample);
if (sha1($strExample) === 'fd4d899c9d520b0569dca7a67c1c5293c36d2400') {
echo "\nWould you like to have php tutorial or html?";
}
$strExample = "Hi";
echo "\nThe string: ".$strExample."\n";
echo "TRUE - Raw 20 character binary format: ".sha1($strExample, TRUE)."\n";
echo "FALSE - 40 character hex number: ".sha1($strExample)."\n";
?>Output of above code in the browser is as below:
Would you like to have php tutorial or html?
The string: Hi
TRUE – Raw 20 character binary format: ÝÁ)Ç ÷òVè/¾0æÑ®@
FALSE – 40 character hex number: 94dd9e08c129c785f7f256e82fbe0a30e6d1ae40
