Home >Backend Development >PHP Tutorial >PHP custom hash function example_PHP tutorial
This article describes the implementation method of php custom hash function. Share it with everyone for your reference. The specific analysis is as follows:
Here is a demonstration of a simple hash algorithm implemented in PHP, which can be used for encryption, but this function is too simple and cannot be used for decryption
?
2 3
4 56 |
function SimpleHash($str){
$n = 0;
// The magic happens here:
// I just loop trough all letters and add the
// ASCII value to a integer variable.
for ($c=0; $c < strlen($str); $c )
$n = ord($str[$c]);
// After we went trough all letters
// we have a number that represents the
// content of the string
return $n;
}
|
1 2 3 | $TestString = 'www.jb51.net'; print SimpleHash($TestString); // returns: 1082 |