spechal.com | [spesh-uhl]

Nov/09

15

PHP function to emulate MySQL UUID

/**
   *  uuid
   *
   *  uuid() simply replicates MySQL's UUID function, which returns a 36
   *  character "random" hash (32 alphanumeric, 4 dashes).
   *  @return string
   */
  function uuid(){
    return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
      mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff),
      mt_rand(0, 0x0fff) | 0x4000,
      mt_rand(0, 0x3fff) | 0x8000,
      mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff));
  }

RSS Feed

No comments yet.

Leave a comment!

<<

>>

Find it!

Theme Design by devolux.org