PHP sha1() function

The sha1() function calculate the sha1 hash of a string

Syntax

sha1 ( string $string ,raw_output=FALSE) : string

Parameters

Parameter Name Descrption
$string Required, The string.
raw_output Optional, Specifies the raw_output for hexadecimal number or binary format
  • TRUE - Raw 20 character binary format
  • FALSE(Default) - 40 character hexadecimal number

Return Value

When TRUE - Raw 20 bit character format, When FALSE- 40 character hexadecimal number

sha1() examples

echo sha1('test');
//Output :: a94a8fe5ccb19ba61c4c0873d391e987982fbbd3

if(sha1('test')=='a94a8fe5ccb19ba61c4c0873d391e987982fbbd3')
 echo 1;
else
 echo 0;

Related Functions

  • sha1_file(): Calculate the sha1 hash of a file
  • crc32(): Calculates the crc32 polynomial of a string
  • crypt(): One-way string hashing
  • md5(): Calculate the md5 hash of a string
  • md5_file(): Calculates the md5 hash of a given file