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设置头信息及取得返回头信息的方法

本文实例讲述了PHP设置头信息及取得返回头信息的方法。分享给大家供大家参考,具体如下: 设置请求的头信息,我们可以用header函数,可以用fsockopen,可以用curl等,本文主要...

PHP中for循环语句的几种变型

PHP中for循环语句的几种变型˂!-- google 的广告条 2005年09月20日换位置 唉,22号被停了.郁闷,没作弊呀 11.27日重开了 ˂!-- goog...

php封装db类连接sqlite3数据库的方法实例

前言 SQLite3扩展名在PHP 5.3.0+以上都会默认启用。可以在编译时使用--without-sqlite3来禁用它。 Windows用户可通过启用php_sqlite3.dll...

PHP截取汉字乱码问题解决方法mb_substr函数的应用

首先 1.确保你的Windows/system32下有php_mbstring.dll这个文件,没有就从你Php安装目录extensions里拷入Windows/system32里面。...

php 静态化实现代码

模板文件template.htm: 复制代码 代码如下:<html> <head> <title>%title%</title> <...