这篇文章主要为大家详细介绍了php 自定义一个简单hash函数示例,具有一定的参考价值,可以用来参考一下。
php实现的一个简单hash算法,可以用来加密,不过这个函数过于简单,不能用来解密,php自定义一个简单的hash函数,感兴趣的小伙伴,下面一起跟随512笔记的小编罗X来看看吧。
经测试代码如下:
/**
* 简单hash算法
*
* @param
* @arrange (512.笔记) www.512pic.com
**/
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.512pic.com';
print SimpleHash($TestString);
// returns: 1620
/*** 来自512笔记(www.512pic.com) ***/
注:关于php 自定义一个简单hash函数示例的内容就先介绍到这里,更多相关文章的可以留意512笔记的其他信息。
关键词:HASH