php自定义hash函数实例

yipeiwu_com5年前PHP代码库

本文实例讲述了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.jb51.net';
print SimpleHash($TestString); 
// returns: 1082

希望本文所述对大家的php程序设计有所帮助。

相关文章

php mail to 配置详解

复制代码 代码如下: [mail function] ; For Win32 only. SMTP = mail3.focuschina.com smtp_port = 25 ; For...

php生成图形验证码几种方法小结

我们先来检查一下自己的php是不是打开了gd库。复制代码 代码如下:<?phpif(extension_loaded('gd')) {  echo '你可以使用gd<...

php socket通信(tcp/udp)实例分析

本文实例讲述了php socket通信(tcp/udp)方法。分享给大家供大家参考,具体如下: 注意 1.在socket_bind的时候ip地址不能真回环地址如127.0.0.1 2.s...

PHP单例模式应用示例【多次连接数据库只实例化一次】

本文实例讲述了PHP单例模式应用。分享给大家供大家参考,具体如下: 以前刚开始工作的时候经常连接数据库,每次用到数据库的时候就要用new进行实例并连接一次,当时因为连接数据库的次数不是很...

PHP实现递归无限级分类

PHP实现递归无限级分类

在一些复杂的系统中,要求对信息栏目进行无限级的分类,以增强系统的灵活性。那么PHP是如何实现无限级分类的呢?我们在本文中使用递归算法并结合mysql数据表实现无限级分类。 递归,简单的说...