How can I limit the md5() function PHP to generate 8 random caharacters and numbers?
How can I limit the following code to generate 8 mixed characters and number in the code below.
Here is the PHP code.
md5(uniqid(rand(1,开发者_开发百科6)));
A md5 hash is always 32 characters long ; that's what an md5 is.
But you could choose to use only 8 characters from the string returned by the md5()
function, with the substr
function.
For example, to keep only the first eight characters, you could use something like this :
echo substr(md5(uniqid(rand(1,6))), 0, 8);
And it would get you something like this :
4651da2b
精彩评论