Sunday, July 15, 2007

No Posts and how to make a GUID

There's not been any posts for quite a while now. Sorry for that, but been working on a couple of projects, building an "apartment", and also a new web/mobile project which is due for release tomorrow. I'll post the link(s) then!

For now I'll post a piece of PHP code that I was required to write for a RPC this project. Might come in handy to some (win32) users.

/**
 * Creates a unique GUID string.
 *
 * @return string Unique GUID
 */
function makeGUID()
{
  $ls = Array(8,4,4,4,12);
  $chrs = "0123456789abcdef";
  $guid = "";
  $chlen = strlen($chrs)-1;
  foreach($ls as $len) {
    if($guid != "")
      $guid .= "-";
    for($i=0; $i<$len; $i++)
      $guid .= $chrs[rand(0, $chlen)];
  }
  return $guid;
}

No comments:

Post a Comment