php自定义hash函数实例

yipeiwu_com6年前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中日期加减法运算实现代码

1、首先通过strtotime()获得日期的时间戳 2、获得N天前得时间戳,通过”当前时间戳 - N天的秒数 = N天前得时间戳“ 3、对N天前得时间戳用date()函数进行格式转换 下...

PHP字符串中插入子字符串方法总结 原创

本文实例讲述了PHP字符串中插入子字符串方法。分享给大家供大家参考,具体如下: 首先来看看一个网上常见的方法: 方法一:字符串遍历 function str_insert($str,...

PHP数据集构建JSON格式及新数组的方法

自己写了个PHP结果集转换成JSON格式的函数,可以直接调用:复制代码 代码如下:function RecordToJson($recordset) { $jstr='['; while...

php中使用session防止用户非法登录后台的方法

本文实例讲述了php中使用session防止用户非法登录后台的方法。分享给大家供大家参考。具体如下: 一般来说,我们登录网站后台时,服务器会把登录信息保存到session文件里,并通过读...

php5编程中的异常处理详细方法介绍

1 首先是try,catch  <?php  $path = "D:\\\\in.txt";  try //检...