Home >Backend Development >PHP Tutorial >PHP custom hash function example, phphash function_PHP tutorial
The example in 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. However, this function is too simple and cannot be used for decryption
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; }
Calling method:
$TestString = 'www.jb51.net'; print SimpleHash($TestString); // returns: 1082
I hope this article will be helpful to everyone’s PHP programming design.