在PHP中生成随机(字母数字)字符串

时间:2011-01-30 12:25:07

标签: php

  

可能重复:
  Generating (pseudo)random alpha-numeric strings

如何在PHP中生成随机字符串?数字不是问题,但如何处理字母有效

1 个答案:

答案 0 :(得分:0)

您可能最好将正常随机函数与chr结合使用 来自php手册评论:http://php.net/manual/en/function.chr.php

<?php
for($i=0; $i<7; $i++){
    $random_string .= chr(rand(0,25)+65);
}
echo $random_string;
?>
相关问题