日期:2014-05-17 浏览次数:20550 次
<?php function BKDRHash($str) { $seed = 131; // 31 131 1313 13131 131313 etc.. $hash = 0; $cnt = strlen($str); for($i = 0; $i < $cnt; $i++) { $hash = ((floatval($hash * $seed) & 0x7FFFFFFF) + ord($str[$i])) & 0x7FFFFFFF; } return ($hash & 0x7FFFFFFF); } echo BKDRHash('ggsonic');//1471979560 echo BKDRHash('asdfasdfasdf123'); // 1220655578 ?>