Skip to content

Instantly share code, notes, and snippets.

@ivanvermeyen
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivanvermeyen/242332d9cc997cddaa7a to your computer and use it in GitHub Desktop.
Save ivanvermeyen/242332d9cc997cddaa7a to your computer and use it in GitHub Desktop.
Generate a Unique ID
<?php
class UUID {
/**
* @var
*/
public $prefix;
/**
* @var
*/
public $entropy;
/**
* @param string $prefix
* @param bool $entropy
*/
public function __construct($prefix = '', $entropy = false)
{
$this->uuid = uniqid($prefix, $entropy);
}
/**
* Limit the UUID by a number of characters
*
* @param $length
* @param int $start
* @return $this
*/
public function limit($length, $start = 0)
{
$this->uuid = substr($this->uuid, $start, $length);
return $this;
}
/**
* @return string
*/
public function __toString()
{
return $this->uuid;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment