abstract:本文實(shí)例講述了php自定義hash函數(shù)實(shí)現(xiàn)方法。分享給大家供大家參考。具體分析如下:這里演示php實(shí)現(xiàn)的一個(gè)簡(jiǎn)單hash算法,可以用來(lái)加密,不過這個(gè)函數(shù)過于簡(jiǎn)單,不能用來(lái)解密function SimpleHash($str){ $n = 0; // The magic happe
本文實(shí)例講述了php自定義hash函數(shù)實(shí)現(xiàn)方法。分享給大家供大家參考。具體分析如下:
這里演示php實(shí)現(xiàn)的一個(gè)簡(jiǎn)單hash算法,可以用來(lái)加密,不過這個(gè)函數(shù)過于簡(jiǎn)單,不能用來(lái)解密
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; }
調(diào)用方法:
$TestString = 'www.jb51.net'; print SimpleHash($TestString); // returns: 1082
更多關(guān)于php自定義hash函數(shù)實(shí)例請(qǐng)關(guān)注PHP中文網(wǎng)(www.miracleart.cn)其他文章!