The goal is to store the hash on a mysql database, using INT (not BIGINT or MEDIUMINT).
md5('string', true)
returns binary data, 16 bytes of hash. I thought i could grep the first 4 bytes and convert it to an INT(32bit/4bytes) integer, but i don't know how to do it.
What do you suggest? Thanks.
Use crc32
, it will return a 32bit int
.
var_dump (crc32 ("hello world"));
var_dump (crc32 ("world hello"));
output
int(222957957)
int(1292159901)
Generates the cyclic redundancy checksum polynomial of 32-bit lengths of the str. This is usually used to validate the integrity of data being transmitted.
Because PHP's integer type is signed, and many crc32 checksums will result in negative integers, you need to use the "%u" formatter of sprintf() or printf() to get the string representation of the unsigned crc32 checksum.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With