This function generates a hash containing evenly spaced [az] characters:
function my_hash($string, $length = 8) { // Convert to a string which may contain only characters [0-9a-p] $hash = base_convert(md5($string), 16, 26); // Get part of the string $hash = substr($hash, -$length); // In rare cases it will be too short, add zeroes $hash = str_pad($hash, $length, '0', STR_PAD_LEFT); // Convert character set from [0-9a-p] to [az] $hash = strtr($hash, '0123456789', 'qrstuvwxyz'); return $hash; }
By the way, if this is important for you, for 100,000 different lines you will have a ~ 2% chance of a hash collision (for an 8-hour hash), and for a million lines this chance rises to ~ 90% if my math is correct.
Alexander Konstantinov
source share