note 52817 deleted from function.crc32 by nlopess
| From: | nlopess@php.net | Date: | Sun, 21 Jan 2007 15:51:43 +0000 |
| Subject: | note 52817 deleted from function.crc32 by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-121999@lists.php.net to get a copy of this message | ||
Note Submitter: Johan
----
Here is a php version of the Java String hashCode:
( produced for: http://openmusic.op.funpic.org/catalog/ )
/**
* Calculate hash code for a string computed as
* s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
* Equal to java.lang.String.hashCode()
*
* Returns an integer.
*/
function toID($link) {
$link = (string)$link;
$len = strLen($link);
$sum = 0;
for ($i = 0; $i < $len; $i++) {
$sum = (int)(31 * $sum + getASCIICode($link[$i]));
// echo($sum . "<br>");
}
return ((int)$sum);
}
// get char as int, - see example codes at intval on the subject.
function getASCIICode($caracter) {
// ...
}