create a sha1 hash from a string in php

To create a SHA1 hash from a string in PHP, you can use the sha1() function. This function returns a 40-character string that represents the SHA1 hash of the input string.

Here is an example code snippet:

main.php
$input_string = "Hello, world!";
$sha1_hash = sha1($input_string);

echo "Input string: " . $input_string . "<br>";
echo "SHA1 hash: " . $sha1_hash;
149 chars
6 lines

Output:

main.php
Input string: Hello, world!
SHA1 hash: f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0
80 chars
3 lines

In this example, the input string is "Hello, world!" and the resulting SHA1 hash is "f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0".

related categories

gistlibby LogSnag