w3resource logo


PHP sha1 function

PHP : sha1() function

<<PreviousNext>>

Description

The sha1() function is used to calculate the sha1 hash of a string.

Version

(PHP 4 and above)

Syntax

sha1(string1, raw_output)

Parameter

Name Description Required /
Optional
Type
string1 The input string. Required String
raw_output If TRUE sets raw 20 character binary format. If FALSE (default) sets raw 40 character hex number format. Optional Boolean

Return value

Returns the sha1 hash as a string.

Value Type : String.

Example :

<?php $str = 'Good Morning'; echo sha1($str).'<br>'; echo sha1($str,TRUE).'<br>'; ?>

Output :

06e336231466d0b0573a05cbca7813444afb5b29
ã6#fаW:ËÊxDJû[)

View the example in the browser

See also

PHP Function Reference

<<PreviousNext>>