Given i have these codes of javascripts. I already tried to convert it to PHP but it only returns #000000
function getuidcolor(str) {
var hash = 0;
for (var i = 0; i < str.length; i++) {
hash = str.charCodeAt(i) + ((hash << 5) - hash);
}
var colour = '#';
for (var i = 0; i < 3; i++) {
var value = (hash >> (i * 8)) & 0xFF;
colour += ('00' + value.toString(16)).substr(-2);
}
return colour;
}
What i have so far:
function string2color($str) {
$hash = 0;
for ($i = 0; $i < strlen($str); $i++) {
$hash = $str[$i].(($hash << 5) - $hash);
}
$colour = '#';
for ($i = 0; $i < 3; $i++) {
$value = ($hash >> ($i * 8)) & '0xFF';
$hex = '00' . base_convert($value, 10, 16);
$colour .= substr($hex, -2);
}
return $colour;
}
echo string2color('dfgdgfdgfdgfdgfdg');
My PHP so far works without any errors but it does not really return what it supposed to.