
php生成8位不重复字符串
我们在制作网页时会遇到获取随机数,随机字符串的需求,下面介绍一种方法,产生随机8位不重复字符串:
function randString() {
$code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$rand = $code[rand(0,25)]
.strtoupper(dechex(date('m')))
.date('d').substr(time(),-5)
.substr(microtime(),2,5)
.sprintf('%02d',rand(0,99));
for(
$a = md5( $rand, true ),
$s = '0123456789ABCDEFGHIJKLMNOPQRSTUV',
$d = '',
$f = 0;
$f <p>使用</p><div class="aritcle_card flexRow artxards">
<div class="artcardd flexRow">
<a class="aritcle_card_img" rel="nofollow" href="/xiazai/skill2138" title="PHP"><img
src="https://img.php.cn/upload/skill/000/000/081/178884013267959.jpg" alt="PHP" onerror="this.onerror='';this.src='/static/lhimages/moren/morentu.png'" ></a>
<div class="aritcle_card_info flexColumn">
<a rel="nofollow" href="/xiazai/skill2138" title="PHP" class="overflowclass">PHP</a>
<p class="overflowclass">编写健壮的PHP代码,规避类型转换陷阱、数组怪癖及常见安全漏洞。</p>
</div>
<a rel="nofollow" href="/xiazai/skill2138" title="PHP" class="aritcle_card_btn flexRow flexcenter"><b></b><span>下载</span>
</a>
</div>
</div><pre class="brush:php;toolbar:false">echo randString().'<br>';
echo randString().'<br>';
echo randString().'<br>';结果
RAUHT68I PMI8FO50 O6KFACQ8
更多PHP相关知识,请访问PHP中文网!
php免费学习视频:立即使用
踏上前端学习之旅,开启通往精通之路!从前端基础到项目实战,循序渐进,一步一个脚印,迈向巅峰!










