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面向对象程序设计之对象克隆clone和魔术方法__clone()用法分析

本文实例讲述了PHP面向对象程序设计之对象克隆clone和魔术方法__clone()用法。分享给大家供大家参考,具体如下: 1.对象克隆 clone PHP4面向对象功能一个很大的缺点,...

php表单请求获得数据求和示例

获得表单请求的值: 案例: request.php 复制代码 代码如下: <html> <head> <meta http-equiv="content-t...

PHP has encountered a Stack overflow问题解决方法

昨晚将一个disucz论坛进行转移后,发现打开的页面上回多一个PHP has encountered a Stack overflow 这个提示错误,进过翻译为“PHP遇到堆栈溢出”。我...

通俗易懂的php防注入代码

介绍两种方法吧,首先请把以下代码保存为safe.php放在网站根目录下,然后在每个php文件前加include(“/safe.php“);即可 : php防注入代码方法一: 复制代码 代...

详谈配置phpstorm完美支持Codeigniter(CI)代码自动完成(代码提示)

详谈配置phpstorm完美支持Codeigniter(CI)代码自动完成(代码提示)

1、设置字体、风格 代码主题选择Monokai会是彩色的代码。 2、配置CI代码提示 <1>下载代码提示项目: https://github.com/topdown/p...