1

Possible Duplicate:
PHP function to generate v4 UUID

I've been looking all over the web for this. Im trying to make a UUID which will appear in this format: 32321-65631-43546-54542 (the numbers of course, will vary) I know how to make a uniqid id, but dont know where to start with this. Anybody know how this can be accomplished?

Community
  • 1
  • 1
user719813
  • 583
  • 3
  • 11
  • 18
  • 2
    Should this “UUID” comply with some [specific requirements](http://en.wikipedia.org/wiki/Universally_unique_identifier)? – Gumbo Jun 16 '11 at 17:15
  • no, i just want it to generate a 4 sectioned id with 5 numbers in each section. – user719813 Jun 16 '11 at 17:20
  • I don't see how my answer below can't do this? Generate 4 5 digit numbers and switch the x's to d's if you are only going to be used decimals rather than hex. – Colin Jun 16 '11 at 17:29
  • You can use either one of these generators to easily create UUID or GUIDs (basically same thing): [Online UUID Generator](http://www.onlineuuidgenerator.com) [Online GUID Generator](http://www.onlineguidgenerator.com) – Dave May 08 '12 at 18:21

2 Answers2

3

You can find your answer here:

PHP function to generate v4 UUID

and here

http://php.net/manual/en/function.uniqid.php

Second Edit

Using the answer in the first link:

$uuid = sprintf('%05d-%05d-%05d-%05d',
  mt_rand( 0, 99999),
  mt_rand( 0, 99999),
  mt_rand( 0, 99999),
  mt_rand( 0, 99999)
 );

Bear in mind this is not a 'proper' UUID, as it is not going to be Universally unique (among other things). This is really just a random 20 digit hyphenated ID.

Community
  • 1
  • 1
Colin
  • 2,001
  • 13
  • 28
3

If I understand you question correctly: You have your number (...I know how to make a uniqid id...), but are searching for a way to format it properly, try this:

$number = '32321656314354654542';
echo implode('-', str_split($number, 5));

Output:

32321-65631-43546-54542
Yoshi
  • 54,081
  • 14
  • 89
  • 103