I have gone through this page…
http://www.php.net/manual/en/function.hash.php
MD5 is 32 characters long while sha1 is 40.
For e.g.
$str = 'apple';
sha1 string d0be2dc421be4fcd0172e5afceea3970e2f3d940
md5 string 1f3870be274f6c49b3e31a0c6728957f
Even if the optional raw_output is set to TRUE, then the md5 digest is instead returned in raw binary format with a length of 16.
I am looking for a function that will create hash that will be equal or less than 8 characters.
Update:
I need smaller strings for 3 reasons:
1) MySQL Archive table type does not seem to allow an index on a column that has more than 8 chars
2) I am planning to use key-value utility like redis that likes smaller keys
3) Security is not an issue here. I am hashing columns like “country + telco + operator”
You can use the
crc32method to create the hash, it creates an 8 character long hash.Be extremely cautious with this method, as it is totally exposed to cryptographic attacks. Do NOT use this for any sort of security cheking.