How to hash a string with SHA-256 in PHP

1 Answer

0 votes
function sha256(string $input): string {
    // hash() returns a lowercase hex string by default
    return hash('sha256', $input);
}

$input = "PHP programming language";
$hash = sha256($input);

echo $hash . PHP_EOL;



/*
run:

2d4cfd679f3faa497d21fc551e081cd49da5f1c386f76eb70845e3d0ebc208e0

*/

 



answered 9 hours ago by avibootz
...