php: number only hash?

后端 未结 7 1988
眼角桃花
眼角桃花 2020-12-03 01:00

In php is there a way to give a unique hash from a string, but that the hash was made up from numbers only?

example:

return md5(234); // returns 098f         


        
7条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-03 01:11

    First of all, md5 is basically compromised, so you shouldn't be using it for anything but non-critical hashing. PHP5 has the hash() function, see http://www.php.net/manual/en/function.hash.php.

    Setting the last parameter to true will give you a string of binary data. Alternatively, you could split the resulting hexadecimal hash into pieces of 2 characters and convert them to integers individually, but I'd expect that to be much slower.

提交回复
热议问题