mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-18 05:26:57 +08:00
118 lines
6.1 KiB
HTML
118 lines
6.1 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||
<html>
|
||
<head>
|
||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||
<title>生成一个唯一ID</title>
|
||
</head>
|
||
<body class="docs"><div id="layout">
|
||
<div id="layout-content"><div id="function.uniqid" class="refentry">
|
||
<div class="refnamediv">
|
||
<h1 class="refname">uniqid</h1>
|
||
<p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">uniqid</span> — <span class="dc-title">生成一个唯一ID</span></p>
|
||
|
||
</div>
|
||
|
||
<div class="refsect1 description" id="refsect1-function.uniqid-description">
|
||
<h3 class="title">说明</h3>
|
||
<div class="methodsynopsis dc-description">
|
||
<span class="methodname"><strong>uniqid</strong></span>
|
||
([ <span class="methodparam"><span class="type">string</span> <code class="parameter">$prefix</code><span class="initializer"> = ""</span></span>
|
||
[, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$more_entropy</code><span class="initializer"> = false</span></span>
|
||
]] ) : <span class="type">string</span></div>
|
||
|
||
<p class="para rdfs-comment">
|
||
获取一个带前缀、基于当前时间微秒数的唯一ID。
|
||
</p>
|
||
<div class="caution"><strong class="caution">Caution</strong><p class="para">本函数并不会生成安全加密的值,不应用于加密用途。若需要安全加密的值,考虑使用<span class="function"><a href="openssl_random_pseudo_bytes.html" class="function">openssl_random_pseudo_bytes()</a></span>。</p></div>
|
||
<div class="warning"><strong class="warning">Warning</strong>
|
||
<p class="para">
|
||
此函数不保证返回值的唯一性。
|
||
由于绝大多数系统使用 NTP 或者类似服务调整系统的时间,所以系统时间经常发生变化。
|
||
此外,进程/线程可能不会返回唯一的 ID。
|
||
用 <code class="parameter">more_entropy</code> 来增加唯一性的概率。
|
||
</p>
|
||
</div>
|
||
</div>
|
||
|
||
|
||
<div class="refsect1 parameters" id="refsect1-function.uniqid-parameters">
|
||
<h3 class="title">参数</h3>
|
||
<p class="para">
|
||
<dl>
|
||
|
||
|
||
<dt>
|
||
<code class="parameter">prefix</code></dt>
|
||
|
||
<dd>
|
||
|
||
<p class="para">
|
||
有用的参数。例如:如果在多台主机上可能在同一微秒生成唯一ID。
|
||
</p>
|
||
<p class="para">
|
||
<code class="parameter">prefix</code>为空,则返回的字符串长度为13。<code class="parameter">more_entropy</code> 为
|
||
<strong><code>TRUE</code></strong>,则返回的字符串长度为23。
|
||
</p>
|
||
</dd>
|
||
|
||
|
||
|
||
<dt>
|
||
<code class="parameter">more_entropy</code></dt>
|
||
|
||
<dd>
|
||
|
||
<p class="para">
|
||
如果设置为 <strong><code>TRUE</code></strong>,<span class="function"><strong>uniqid()</strong></span> 会在返回的字符串结尾增加额外的熵(使用combined linear congruential generator)。
|
||
使得唯一ID更具唯一性。
|
||
</p>
|
||
</dd>
|
||
|
||
|
||
</dl>
|
||
|
||
</p>
|
||
</div>
|
||
|
||
|
||
<div class="refsect1 returnvalues" id="refsect1-function.uniqid-returnvalues">
|
||
<h3 class="title">返回值</h3>
|
||
<p class="para">
|
||
返回字符串形式的唯一ID。
|
||
</p>
|
||
<div class="warning"><strong class="warning">Warning</strong>
|
||
<p class="para">
|
||
此函数努力创建唯一识别符,但它不保证返回值得唯一性。
|
||
</p>
|
||
</div>
|
||
</div>
|
||
|
||
|
||
<div class="refsect1 examples" id="refsect1-function.uniqid-examples">
|
||
<h3 class="title">范例</h3>
|
||
<p class="para">
|
||
<div class="example" id="example-4552">
|
||
<p><strong>Example #1 <span class="function"><strong>uniqid()</strong></span> 例子</strong></p>
|
||
<div class="example-contents">
|
||
<div class="phpcode"><pre><span style="color: #000000">
|
||
<span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">/* A uniqid, like: 4b3403665fea6 */<br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"uniqid(): %s\r\n"</span><span style="color: #007700">, </span><span style="color: #0000BB">uniqid</span><span style="color: #007700">());<br /><br /></span><span style="color: #FF8000">/* We can also prefix the uniqid, this the same as <br /> * doing:<br /> *<br /> * $uniqid = $prefix . uniqid();<br /> * $uniqid = uniqid($prefix);<br /> */<br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"uniqid('php_'): %s\r\n"</span><span style="color: #007700">, </span><span style="color: #0000BB">uniqid</span><span style="color: #007700">(</span><span style="color: #DD0000">'php_'</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">/* We can also activate the more_entropy parameter, which is <br /> * required on some systems, like Cygwin. This makes uniqid()<br /> * produce a value like: 4b340550242239.64159797<br /> */<br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"uniqid('', true): %s\r\n"</span><span style="color: #007700">, </span><span style="color: #0000BB">uniqid</span><span style="color: #007700">(</span><span style="color: #DD0000">''</span><span style="color: #007700">, </span><span style="color: #0000BB">true</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?></span>
|
||
</span>
|
||
</pre></div>
|
||
</div>
|
||
|
||
</div>
|
||
</p>
|
||
</div>
|
||
|
||
|
||
<div class="refsect1 notes" id="refsect1-function.uniqid-notes">
|
||
<h3 class="title">注释</h3>
|
||
<blockquote class="note"><p><strong class="note">Note</strong>:
|
||
<p class="para">
|
||
在Cygwin环境下,为了使此函数能够工作,<code class="parameter">more_entropy</code> 必须设置为 <strong><code>TRUE</code></strong>。
|
||
</p>
|
||
</p></blockquote>
|
||
</div>
|
||
|
||
|
||
</div></div></div></body></html> |