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 strtotime 函数UNIX时间戳

如果 time 的格式是绝对时间则 now 参数不起作用。如果 time 的格式是相对时间则其所相对的时间由 now 提供,或者如果未提供 now 参数时用当前时间。失败时返回 -1。...

PHP 线程安全与非线程安全版本的区别深入解析

从2000年10月20日发布的第一个Windows版的PHP3.0.17开始的都是线程安全的版本,这是由于与Linux/Unix系统是采用多进程的工作方式不同的是Windows系统是采用...

PHP实现将科学计数法转换为原始数字字符串的方法

本文实例讲述了PHP实现将科学计数法转换为原始数字字符串的方法,分享给大家供大家参考。 具体实现代码如下: 复制代码 代码如下:function NumToStr($num){ &nb...

PHP 批量删除数据的方法分析

大家可以参考下面的这篇文章https://www.jb51.net/article/6488.htmSQL:$SQL="delete from `doing` where id in (...

php图形jpgraph操作实例分析

本文实例讲述了php图形jpgraph操作。分享给大家供大家参考,具体如下: <?php include ("src/jpgraph.php"); include("s...