如何在PHP中使用模式生成34个字母数字? [英] How to generate 34 alphanumerics with a pattern in PHP?
本文介绍了如何在PHP中使用模式生成34个字母数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想生成34个随机字母(大写和非大写)和数字.在生成34个随机字母数字之前,有一个 pro_sec _ 字,它每次生成时都存在.还有25号和25号26号是 00
I want to generate 34 random letters (capitalized and not) and numbers. Before the generated 34 random alphanumerics there is a word pro_sec_ which is there everytime it generate. And the 25th & 26th is 00
因此,生成的结果将是:(仅作为示例)
So the generated result will be: (just an example)
pro_sec_Vy6Q67sh6HvP90j7gWnq6SxN00p8Gapu66
另一个. pro_sec_6B57nTshusbnay6esjabxns800nGvaz2Lov
第25位和第26位的pro_sec_和00始终相同,其余的仅生成.
The pro_sec_ and the 00 there in 25th and 26th are always the same and the rest are just generated.
推荐答案
高性能解决方案,无需使用任何循环或两次调用该函数:
Performant solution without using any loops or calling the function twice:
$chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$split = str_split(substr(str_shuffle($chars), 0, 32), 25);
$res = 'pro_sec_'.$split[0].'00'.$split[1];
echo $res; // pro_sec_c8s5iwyQY0nZoJf73EOkC9vqS00dNLWVKg
这篇关于如何在PHP中使用模式生成34个字母数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文