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 获取页面中指定内容的实现类

功能: 1.获取内容中的url,email,image。 2.替换内容中的url,email,image。 url:<a href="url">xxx</a> e...

PHP栈的定义、入栈出栈方法及基于堆栈实现的计算器完整实例

本文实例讲述了PHP栈的定义、入栈出栈方法及基于堆栈实现的计算器。分享给大家供大家参考,具体如下: 栈是线性表的一种,他的特点是后入先出,可以这么理解,栈就像一个存东西的盒子,先放进去的...

php使用正则验证中文

php用preg_match来匹配并判断一个字符串中是否含有中文或者都是中文的方法如下: $str = 'php学习博客'; if(preg_match('/[\x7f-\xff]/...

ThinkPHP实现登录退出功能

本文实例为大家分享了ThinkPHP实现登录退出功能的具体代码,供大家参考,具体内容如下 <?php /** * 用户登陆与退出 * 注册成功后,将页面跳转到lo...

php+jQuery递归调用POST循环请求示例

php+jQuery递归调用POST循环请求示例

本文实例讲述了php+jQuery递归调用POST循环请求的方法。分享给大家供大家参考,具体如下: jQuery 代码部分: $(function(){ _post('demo.p...