這篇文章主要介紹了php自定義hash函數,實例分析了hash函數的實現技巧,可實現簡單的加密功能,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了php自定義hash函數實現方法。分享給大家供大家參考。具體分析如下:
這里演示php實現的一個簡單hash算法,可以用來加密,不過這個函數過于簡單,不能用來解密
- 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;
- }
調用方法:
- $TestString = 'www.49028c.com';
- print SimpleHash($TestString);
- // returns: 1082
希望本文所述對大家的php程序設計有所幫助。
新聞熱點
疑難解答