php生成随机字符串

php使用rand随机函数生成随机字符串

生成一组

<?php
$str = "0123456789abcdefghijklmnopqrstuvwxyz~@#()_";//输出字符集
$n = 10;//输出串长度
$len = strlen($str)-1;

    for($i=0 ; $i<$n; $i++){
        $s .= $str[rand(0,$len)];
    }
    echo $s . "<br/>";
    $s = "";

?>

生成多组

<?php
$str = "0123456789abcdefghijklmnopqrstuvwxyz~@#()_";//输出字符集
$n = 10;//输出串长度
$len = strlen($str)-1;
for($j=0 ; $j<200 ; $j++){
    for($i=0 ; $i<$n; $i++){
        $s .= $str[rand(0,$len)];
    }
    echo $s . "<br/>";
    $s = "";
}
?>

 

posted @ 2013-01-03 14:52  神马和浮云  阅读(4154)  评论(1编辑  收藏  举报