生成随机字符串:PHP生成随机字符串
来源: 发布时间:星期一, 2009年1月12日 浏览:24次 评论:0
PHP生成随机 ![](/icons/51357zifu.gif) 串 ![](/icons/51357de.gif) ![](/icons/51357hanshu.gif) ![](/icons/51357dou.gif) 下面是我在网上找到 ![](/icons/51357de.gif) 2个有关PHP随机 ![](/icons/51357zifu.gif) 串 ![](/icons/51357de.gif) ![](/icons/51357hanshu.gif) ![](/icons/51357dou.gif) 希望大家喜欢 ![](/icons/51357dou2.gif) 第 ![](/icons/51357yi.gif) 个例子 < ?php function genRandomString($len) { $chars = .gif' />( "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ); $charsLen = count($chars) - 1; shuffle($chars); // 将 打乱 $output = ""; for ($i=0; $i<$len; $i ) { $output .= $chars[mt_rand(0, $charsLen)]; } $output; } $str = genRandomString(25); $str .= "<br />"; $str .= genRandomString(25); $str .= "<br />"; $str .= genRandomString(25); echo $str; ?> 第 2个举例 <?php /* Generate Password * Length : 8 */ $str = "0123456789abcdefghijklmnopqrstuvwxyz"; // 输出 集 $n = 8; // 输出串长度 $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 = ""; } ?>
相关文章
读者评论
发表评论
|
|