时间:2021-07-01 10:21:17 帮助过:26人阅读
*/
$validcharacters = "abcdefghijklmnopqrstuxyvwzabcdefghijklmnopqrstuxyvwz+-*#&@!?";
$index = mt_rand(0, 10);
echo $index;
//看一款复杂一点的
$validcharacters = "abcdefghijklmnopqrstuxyvwzabcdefghijklmnopqrstuxyvwz+-*#&@!?";
$validcharnumber = strlen($validcharacters);
$index = mt_rand(0, $validcharnumber-1);
$randomcharacter = $validcharacters[$index];
echo $randomcharacter;
//实例二
$length = 5;
$result = "";
for ($i = 0; $i < $length; $i++) {
$index = mt_rand(0, $validcharnumber-1);
$result .= $validcharacters[$index];
}
//
function getrandomstring($length = 6) {
$validcharacters = "abcdefghijklmnopqrstuxyvwzabcdefghijklmnopqrstuxyvwz+-*#&@!?";
$validcharnumber = strlen($validcharacters);
$result = "";
for ($i = 0; $i < $length; $i++) {
$index = mt_rand(0, $validcharnumber - 1);
$result .= $validcharacters[$index];
}
return $result;
}
echo getrandomstring();
http://www.bkjia.com/PHPjc/631732.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/631732.htmlTechArticlephp教程生成字符串随机码实现方法 */ $validcharacters = abcdefghijklmnopqrstuxyvwzabcdefghijklmnopqrstuxyvwz+-*#@!?; $index = mt_rand(0, 10); echo $index; //看一款复杂...