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使用CURL实现下载文件功能示例

本文实例讲述了PHP使用CURL实现下载文件功能。分享给大家供大家参考,具体如下: 如果使用CURL下载从微信手机端上传的图片?参考下面代码 /** * CURL下载文件 成功返回...

fleaphp rolesNameField bug解决方法

复制代码 代码如下: function fetchRoles($user) { if ($this->existsLink($this->rolesField)) { $li...

PHP正则匹配日期和时间(时间戳转换)的实例代码

先来一个比较简单实用的代码 日期YYYY-MM-DD $str = ''; $isMatched = preg_match('/^\d{4}(\-|\/|.)\d{1,2}\1\d{...

浅析51个PHP处理字符串的函数

包括,计算字符串长度、分割字符串、查找字符串等等各个方面。1.AddSlashes: 字符串加入斜线。 2.bin2hex: 二进位转成十六进位。 3.Chop: 去除连续空白。 4.C...

PHP用SAX解析XML的实现代码与问题分析

复制代码 代码如下: <?php $g_books = array(); $g_elem = null; function startElement( $parser, $name...