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程序设计有所帮助。

相关文章

学习使用curl采集curl使用方法

复制代码 代码如下: <?php $cookie_jar = tempnam('./tmp','cookie'); $ch = curl_init(); curl_setopt($...

PHP简单实现断点续传下载的方法

本文实例讲述了PHP实现断点续传下载的方法。分享给大家供大家参考。具体如下: $fname = 'http://XXXX/MMLDZG.mp3'; $fp = fopen($fnam...

采用header定义为文件然后readfile下载(隐藏下载地址)

复制代码 代码如下:<?php function sendFile($fileName, $fancyName = '', $forceDownload = true, $spee...

php通过排列组合实现1到9数字相加都等于20的方法

本文实例讲述了php通过排列组合实现1到9数字相加都等于20的方法。分享给大家供大家参考。具体实现方法如下: <?php set_time_limit(0); /* 函...

PHP对象相互引用的内存溢出实例分析

通常来说使用脚本语言最大的好处之一就是可利用其拥有的自动垃圾回收机制来释放内存。你不需要在使用完变量后做任何释放内存的处理,因为这些PHP会帮你完成。 当然,我们可以按自己的意愿调用 u...