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 定义404页面的实现代码

核心代码: 复制代码 代码如下: @header("http/1.1 404 not found"); @header("status: 404 not found"); echo 'e...

PHP遍历数组的方法汇总

今天有个朋友问我一个问题php遍历数组的方法,告诉她了几个。顺便写个文章总结下,如果总结不全还请朋友们指出 第一、foreach() foreach()是一个用来遍历数组中数据的最简...

PHP iconv 解决utf-8和gb2312编码转换问题

终于皇天不负有心人,答案还是让我找到了。 网上的都是这样用的 复制代码 代码如下:$content = iconv("utf-8","gb2312",$content); 这样做其实也对...

PHP中判断变量为空的几种方法小结

1. isset功能:判断变量是否被初始化 说明:它并不会判断变量是否为空,并且可以用来判断数组中元素是否被定义过注意:当使用isset来判断数组元素是否被初始化过时,它的效率比arra...

深入extjs与php参数交互的详解

复制代码 代码如下:<html> <head>  <title>HelloWorld</title>&nbs...