any one can help me to convert this function to generate hash Code to php i try to convert but not working
function hashCode(str) {
let hash = 0;
for (let i = 0; i < str.length; i++) {
let char = str.charCodeAt(i);
hash = ((hash << 5) - hash) + char;
hash = hash & hash; // Convert to 32bit integer
}
hash = hash.toString(16);
if (hash[0] == '-')
{
hash = 'n' + hash.substr(1);
}
return hash;
}
i try this but not wroking
function hashCode($str) {
$str = (string)$str;
$hash = 0;
$len = strlen($str);
if ($len == 0 )
return $hash;
for ($i = 0; $i < $len; $i++) {
$h = $hash << 5;
$h -= $hash;
$h += ord($str[$i]);
$hash = $h;
$hash &= 0xFFFFFFFF;
}
return $hash;
};
User contributions licensed under CC BY-SA 3.0