DeTechn Blog

PHP生成随机字符串

<?php
function generateRandomString($length = 10) { 
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; 
$randomString = ''; 
for ($i&nbsp;=&nbsp;0;&nbsp;$i < $length;&nbsp;$i++) { 
$randomString&nbsp;.=&nbsp;$characters[rand(0, strlen($characters) - 1)]; 
} 
return $randomString; 
?>
<?php
echo generateRandomString(20);
?>

当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »