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异常处理方法实例汇总

本文实例讲述了php异常处理方法。分享给大家供大家参考。具体如下: <?php $path = "D://in.txt"; try //检测异常 { fil...

php解析base64数据生成图片的方法

php解析base64数据生成图片的方法

本文实例讲述了php解析base64数据生成图片的方法。分享给大家供大家参考,具体如下: $base64 = "/9j/4AAQSkZJRgABAQEAkACQAAD/4QCMRXh...

php获取发送给用户的header信息的方法

本文实例讲述了php获取发送给用户的header信息的方法。分享给大家供大家参考。具体分析如下: headers_list函数没有参数,并返回一个数组。返回的数组包含一个数字索引表,包含...

PHP获取文件后缀名的三个函数

选好一种记住,以后需要使用的时候就可以直接使用,或者来本站查看本文也是可以滴。 复制代码 代码如下: <?php //方法一: function extend_1($file_na...

php htmlspecialchars()与shtmlspecialchars()函数的深入分析

定义和用法htmlspecialchars() 函数把一些预定义的字符转换为 HTML 实体。 预定义的字符是:•& (和号) 成为 &•" (双引号)...