php自定义hash函数实例

yipeiwu_com5年前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实现singleton()单例模式实例

本文实例讲述了php实现singleton()单例模式的方法。分享给大家供大家参考。具体实现方法如下: common.php文件如下: 复制代码 代码如下:<?php&nb...

php线性表的入栈与出栈实例分析

本文实例讲述了php线性表的入栈与出栈用法。分享给大家供大家参考。具体如下: <?php $stack = array("Simon", "Elaine"); //定...

php如何利用pecl安装mongodb扩展详解

php如何利用pecl安装mongodb扩展详解

前言 本文主要给大家介绍了关于php利用pecl安装mongodb扩展的相关内容,下面话不多说了,来一起看看详细的介绍吧 环境说明 php7 centos7 mongodb...

PHP使用flock实现文件加锁的方法

本文实例讲述了PHP使用flock实现文件加锁的方法。分享给大家供大家参考。具体分析如下: flock在官方文档里的解释是:flock() 允许你执行一个简单的可以在任何平台中使用的读取...

php 获取百度的热词数据的代码

复制代码 代码如下: <?php /** * 获取百度的热词 * @user 小杰 * @from http://www.isharey.com/?p=354 * @return...