专注于互联网--专注于架构

最新标签
网站地图
文章索引
Rss订阅

首页 »PHP教程 » 生成随机字符串:PHP生成随机字符串 »正文

生成随机字符串:PHP生成随机字符串

来源: 发布时间:星期一, 2009年1月12日 浏览:24次 评论:0
  PHP生成随机下面是我在网上找到2个有关PHP随机希望大家喜欢

  第个例子

< ?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 = "";
}
?>


0

相关文章

读者评论

发表评论

  • 昵称:
  • 内容: