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封装的page分页类完整实例

本文实例讲述了php封装的page分页类。分享给大家供大家参考,具体如下: 类文件: <?php //分页工具类 class Page{ /*...

PHP使用PHPExcel实现批量上传到数据库的方法

PHP使用PHPExcel实现批量上传到数据库的方法

此例子只使用execel2003的.xls文档,若使用的是其他版本,可以保存格式为“Execel 97-2003 工作簿(*.xls)”即.xls文件类型即可! 功能说明:只能上传Exc...

adodb与adodb_lite之比较

adodb与adodb_lite之比较   作者:欣然随风   adodb出世后得到许多PHPer的肯定和支持,树大招风不知什么时候出了个adod...

php下实现在指定目录搜索指定类型文件的函数

复制代码 代码如下:function bdir($dir,$typearr){ $ndir = scandir($dir); foreach ($ndir as $k => $v)...

php使用wordwrap格式化文本段落的方法

本文实例讲述了php使用wordwrap格式化文本段落的方法。分享给大家供大家参考。具体分析如下: wordwrap()函数可以按照指定的固定行长度格式化文本段落,让段落看起来更加整齐...