PHP sha1() Function


The sha1() predifined function is used to calculates the SHA-1 hash of a string.

Syntax
sha1(string,raw)
Parameters
  • string - (Required) Specify the string to be calculated.
  • raw - (optional) Specify hex or binary output format:
  • TRUE - Raw 20 character binary format
  • FALSE - Default. 40 character hex number.
Example
<?php 
    $a = "Hello sir"; 
    echo "The string: ".$a."<br>"; 
    echo "TRUE - Raw 20 character binary format: ".sha1($a, TRUE)."<br>"; 
    echo "FALSE - 40 character hex number: ".sha1($a)."<br>"; 
?>

Output

The string: Hello sir
TRUE - Raw 20 character binary format: �x�أJFU�%V%�e�I G
FALSE - 40 character hex number: 8978c1d8a34a465584255625df65af04490d7f47

Prev Next