2017-05-30 63 views
0

我想生成一個帳戶ID,總用戶帳戶小於500K,所以我想讓帳戶ID儘可能短,所以我想知道如何生成8或16個字符ID使用PHP?如何用8或16個字符創建一個uuid使用php?

+0

參考https://stackoverflow.com/questions/2040240/php -function-to-generate-v4-uuid –

+2

[PHP函數生成v4 UUID]的可能副本(https://stackoverflow.com/questions/2040240/php-function-to-generate-v4-uuid) – Lepidopteron

回答

1

試試這個

echo strtoupper(bin2hex(openssl_random_pseudo_bytes(16))); 

這將產生16個字符的唯一字符串

您可以創建常見功能也

function GUID() { 
    return strtoupper(bin2hex(openssl_random_pseudo_bytes(16))); 
} 
$id = GUID(); 
echo $id; 
+0

這實際上會創建一個32個字符的唯一字符串。 – masterchief

相關問題