maybe this will help you generate a 12 char string that you can pass in a URL, without increasing the risk of collisions

substr(base_convert(md5($string), 16,32), 0, 12);

This is an addition to this answer.

The answer proposes to take the first twelve characters from a 32 character representation of md5. Thus 20 characters of information will be lost - this will result in way more possible collisions.

You can reduce the loss of information by taking the first twelve characters of a 16 character representation (the raw form):

substr(md5($string, true), 0, 12);

This will maintain 75% of the data, whereas the use of the 32 char form only maintains 37.5% of the data.


Try crc32() maybe?


If you just need a hash, you can still use the first 12 characters from the md5 hash.

substr(md5($yourString), 0, 12);