---
title: "PHP生成全球唯一码"
author: "d2hellen"
date: "2013-02-20T09:49:54Z"
tags: []
categories: ["编程语言"]
slug: "php"
draft: false
lastmod: "2013-02-20T09:49:54Z"
id: 1808180
url: "https://lan-hai.iteye.com/blog/1808180"
---

```php

<?
 
function guid() {
	$charid = strtoupper(md5(uniqid(mt_rand(), true)));
	$uuid =
	substr($charid, 0, 8).
	substr($charid, 8, 4). 
	substr($charid,12, 4).
	substr($charid,16, 4).
	substr($charid,20,12); 
	return $uuid; 
}
 echo strlen(guid());
?>

```