w3resource

PHP: sha1() function

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 characters 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

Previous: sha1_file
Next: similar_text



Follow us on Facebook and Twitter for latest update.