diff --git a/src/Check.php b/src/Check.php index cc7ae27..113a6e8 100644 --- a/src/Check.php +++ b/src/Check.php @@ -120,6 +120,20 @@ class Check { } } + /** + * check if an uuid is correct + * + * @access public + * @param string $value The value to check + * @return bool true or false + */ + public static function uuid($value) { + if (preg_match('/^[0-9a-f]{8}\-[0-9a-f]{4}\-[0-9a-f]{4}\-[0-9a-f]{4}\-[0-9a-f]{12}$/',$value)) { + return true; + } + return false; + } + } # vim: tabstop=2 shiftwidth=2 softtabstop=2 expandtab diff --git a/src/functions.php b/src/functions.php index 14bad74..4efae8f 100644 --- a/src/functions.php +++ b/src/functions.php @@ -344,4 +344,30 @@ function implode_with_keys($values, $quoted=true, $separator=', ', $kv_separator return implode($separator, $result); } +/** + * Generate UUID + * @return string UUID + */ +function generate_uuid() { + return sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x', + // 32 bits for "time_low" + mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), + + // 16 bits for "time_mid" + mt_rand( 0, 0xffff ), + + // 16 bits for "time_hi_and_version", + // four most significant bits holds version number 4 + mt_rand( 0, 0x0fff ) | 0x4000, + + // 16 bits, 8 bits for "clk_seq_hi_res", + // 8 bits for "clk_seq_low", + // two most significant bits holds zero and one for variant DCE1.1 + mt_rand( 0, 0x3fff ) | 0x8000, + + // 48 bits for "node" + mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ) + ); +} + # vim: tabstop=2 shiftwidth=2 softtabstop=2 expandtab