Skip to content

Instantly share code, notes, and snippets.

@gormus
Created December 28, 2015 20:58
Show Gist options
  • Save gormus/71359c8a63c0b50e2550 to your computer and use it in GitHub Desktop.
Save gormus/71359c8a63c0b50e2550 to your computer and use it in GitHub Desktop.
Create a GUID.
<?php
$guid = getGUID(array('{','}'));
print $guid;
function getGUID($strip = array()) {
$guid = '';
if (function_exists('com_create_guid')) {
$guid = com_create_guid();
}
else {
mt_srand((double)microtime()*10000);//optional for php 4.2.0 and up.
$charid = strtoupper(md5(uniqid(rand(), true)));
$hyphen = chr(45); // "-"
$guid = chr(123) // "{"
.substr($charid, 0, 8) . $hyphen
.substr($charid, 8, 4) . $hyphen
.substr($charid,12, 4) . $hyphen
.substr($charid,16, 4) . $hyphen
.substr($charid,20,12)
.chr(125); // "}"
}
return str_replace($strip, '', $guid);
}
@gormus
Copy link
Author

gormus commented Aug 21, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment