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中simplexml_load_string函数使用说明

先用一段代码重现一下问题 乍一看,结果很让人费解: 复制代码 代码如下: <?php $string = <<<EOF <data> <foo&...

php封装的数据库函数与用法示例【参考thinkPHP】

本文实例讲述了php封装的数据库函数与用法。分享给大家供大家参考,具体如下: 从Thinkphp里面抽离出来的数据库模块,感觉挺好用 common.php: <?PHP...

最新用php获取谷歌PR值算法,附上php查询PR值代码示例

复制代码 代码如下: /* *功能:对URL进行编码 *参数说明:$web_url 网站URL,不包含"http://",例如jb51.net */ function HashURL($...

php代码中使用换行及(\n或\r\n和br)的应用

代码a: 复制代码 代码如下: <?php echo'hello</br>'; echo'world!'; ?> output: helllo world! 代...

php安装swoole扩展的方法

本文实例讲述了php安装swoole扩展的方法。分享给大家供大家参考。具体如下: 我本机是OS X,想要安装swoole体验一下,于是: 复制代码 代码如下:andy@AndyMacBo...