tags:

views:

24

answers:

1

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)));
+3  A: 

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
Pascal MARTIN
An md5 is 128-bit long (16 bytes). What's 32 bytes long is the hexadecimal representation, since each byte now encodes only a nibble.
Artefacto