유니큐 문자열 생성 함수를 공유해드립니다.
PHP로 중복없는 유일한 문자열을 생성하는 제가 애용하는 함수를 공유해드립니다.
function v4 ($trim = true)
{
// Windows
if (function_exists('com_create_guid') === true) {
if ($trim === true)
return trim(com_create_guid(), '{}');
else
return com_create_guid();
}
// OSX/Linux
if (function_exists('openssl_random_pseudo_bytes') === true) {
$data = openssl_random_pseudo_bytes(16);
$data[6] = chr(ord($data[6]) & 0x0f | 0x40); // set version to 0100
$data[8] = chr(ord($data[8]) & 0x3f | 0x80); // set bits 6-7 to 10
return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
}
// Fallback (PHP 4.2+)
mt_srand((double)microtime() * 10000);
$charid = strtolower(md5(uniqid(rand(), true)));
$hyphen = chr(45); // "-"
$lbrace = $trim ? "" : chr(123); // "{"
$rbrace = $trim ? "" : chr(125); // "}"
$guidv4 = $lbrace.
substr($charid, 0, 8).$hyphen.
substr($charid, 8, 4).$hyphen.
substr($charid, 12, 4).$hyphen.
substr($charid, 16, 4).$hyphen.
substr($charid, 20, 12).
$rbrace;
return $guidv4;
}
이용해주시는 분들께 감사를 드립니다.
게시판 목록
개발자팁
개발과 관련된 유용한 정보를 공유하세요.
질문은 QA에서 해주시기 바랍니다.
질문은 QA에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 5186 | PHP |
swallow
|
2년 전 | 948 | |
| 5185 | PHP |
swallow
|
2년 전 | 964 | |
| 5184 | PHP |
swallow
|
2년 전 | 541 | |
| 5183 | PHP |
swallow
|
2년 전 | 849 | |
| 5182 | PHP |
swallow
|
2년 전 | 779 | |
| 5181 | 기타 |
swallow
|
2년 전 | 1023 | |
| 5180 | 2년 전 | 576 | |||
| 5179 | 기타 |
swallow
|
2년 전 | 1438 | |
| 5178 | PHP |
swallow
|
2년 전 | 798 | |
| 5177 | JavaScript |
swallow
|
2년 전 | 1494 | |
| 5176 | PHP |
swallow
|
2년 전 | 1191 | |
| 5175 | 2년 전 | 568 | |||
| 5174 | 기타 | 2년 전 | 823 | ||
| 5173 | PHP |
|
2년 전 | 971 | |
| 5172 | PHP |
|
2년 전 | 1254 | |
| 5171 | 기타 |
그누GPT
|
2년 전 | 1559 | |
| 5170 | PHP |
|
2년 전 | 1058 | |
| 5169 | PHP |
|
2년 전 | 1229 | |
| 5168 | PHP |
|
2년 전 | 1202 | |
| 5167 | JavaScript |
|
2년 전 | 1001 | |
| 5166 | MySQL | 2년 전 | 1197 | ||
| 5165 | MySQL | 2년 전 | 1259 | ||
| 5164 | PHP | 2년 전 | 1507 | ||
| 5163 | OS |
|
2년 전 | 846 | |
| 5162 | 웹서버 |
|
2년 전 | 897 | |
| 5161 | 웹서버 |
|
2년 전 | 977 | |
| 5160 | PHP |
|
2년 전 | 847 | |
| 5159 | PHP |
|
2년 전 | 911 | |
| 5158 | PHP |
|
2년 전 | 921 | |
| 5157 | PHP |
|
2년 전 | 946 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기