PHP中產生UUID,PHP產生UUID_PHP教程

來源:互聯網
上載者:User

PHP中產生UUID,PHP產生UUID


一、什麼是UUID

  簡單的說UUID就是一串全球唯一的(16進位)數字串。

  UUID的全拼為“Universally Unique Identifier”,可以譯為“通用唯一識別碼”。UUID由開源軟體基金會 (Open Software Foundation, OSF) 定義,是分散式運算環境 (Distributed Computing Environment, DCE) 的一個組成部分。

  UUID的標準格式為“xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx”,五個部分分別為8個字元、4個字元、4個字元、4個字元、12個字元,中間用“-”號間隔。常見的GUID(Globally Unique Identifier)是微軟對UUID標準的一種實現。

二、為什麼要使用UUID

  好處那叫一個多呀~~~,您隨便百度把。

三、UUID的產生代碼

  這個……,真心過時了,用擴充吧,別自己寫代碼了。

四、安裝UUID擴充

  相關的擴充在這裡:PECL :: Package :: uuid。

  PHP擴充安裝步驟一直就是那幾個:

  

wget http://pecl.php.net/get/uuid-1.0.3.tgztar zxvf uuid-1.0.3.tgzcd uuid-1.0.3phpize./configuremakemake install

  好了,然後編輯一下PHP設定檔,重啟一下伺服器,到phpinfo()去看效果吧:

  安裝成功之後,寫兩行代碼測試一下吧:

  

1 php2 //uuid.php3 echo uuid_create(), '
\n';4 echo uuid_create(1); //建議用法

  重新整理幾次頁面,觀察一下兩行UUID的變化,有什麼發現嗎?想進一步瞭解的話,請學習一下UUID的幾個版本是如何定義的吧。

五、安裝擴充可能遇到的問題

  安裝擴充遇到問題一般都是系統缺少相關組件造成的。

  在centos 7中,需要先安裝libuuid-devel,這個用yum命令就可以了。

  在mac os 10.9中則需要先安裝libuuid,這個要到libuuid | SourceForge.net下載。

好了,就這些,有真正的v1 UUID可用了。


linux已經安裝了php擴充uuid 但是還報Call to undefined function uuid_make()這個錯誤,為甚


是否已經有MYSQL
否則
PHP.INI配置有問題
 

js中怎產生uuid

www.broofa.com/Tools/Math.uuid.js

Math.uuid = (function() {

// Private array of chars to use

var CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');

return function (len, radix) {

var chars = CHARS, uuid = [], rnd = Math.random;

radix = radix || chars.length;

if (len) {

// Compact form

for (var i = 0; i < len; i++) uuid[i] = chars[0 | rnd()*radix];

} else {

// rfc4122, version 4 form

var r;

// rfc4122 requires these characters

uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';

uuid[14] = '4';

// Fill in random data. At i==19 set the high bits of clock sequence as

// per rfc4122, sec. 4.1.5

for (var i = 0; i < 36; i++) {

if (!uuid[i]) {

r = 0 | rnd()*16;

uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r & 0xf];

}

}

}

return uuid.join('');

};

})();

// Deprecated - only here for backward compatability

var randomUUID = Math.uuid;

function generateUUID()

{

return Math.uuid();

}...餘下全文>>
 

http://www.bkjia.com/PHPjc/891596.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/891596.htmlTechArticlePHP中產生UUID,PHP產生UUID 一、什麼是UUID 簡單的說UUID就是一串全球唯一的(16進位)數字串。 UUID的全拼為Universally Unique Identifier,可以譯為通...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.