php生产随机字符的代码
2013-04-12 20:51
141 查看
<?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 = "";
}
?>
$str="123456789sfsafsfsafdasd";
$a=0;
$b=20;
$str[a,b] ;//从字符串$str中的0位置开始截取,截取到$str20的位置;
< ?php
function genRandomString($len)
{
$chars = array(
"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)];
}
return $output;
}
$str = genRandomString(25);
$str .= "<br />";
$str .= genRandomString(25);
$str .= "<br />";
$str .= genRandomString(25);
echo $str;
?>
/* 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 = "";
}
?>
$str="123456789sfsafsfsafdasd";
$a=0;
$b=20;
$str[a,b] ;//从字符串$str中的0位置开始截取,截取到$str20的位置;
< ?php
function genRandomString($len)
{
$chars = array(
"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)];
}
return $output;
}
$str = genRandomString(25);
$str .= "<br />";
$str .= genRandomString(25);
$str .= "<br />";
$str .= genRandomString(25);
echo $str;
?>
相关文章推荐
- php 随机生成10位字符代码
- php实现处理输入转义字符的代码
- PHP UTF8中文字符截断函数代码
- PHP 可阅读随机字符串代码
- php按照奖品百分比随机抽奖代码分析
- php 随机排序广告的实现代码
- php中计算未知长度的字符串哪个字符出现的次数最多的代码
- PHP 反向排序和随机排序代码
- PHP生成随机字符方法
- PHP随机生成N个汉字的实现方法(含代码)
- php ucwords() 函数将字符串中每个单词的首字符转换为大写(实现代码)
- php 随机用户名与随机密码生成代码
- ASP页面随机添加字符实现防复制的代码
- PHP 一个随机字符串生成代码
- php替换超长文本中的特殊字符的函数代码
- [PHP]查看用户IP&查看当前字符设置代码
- php从mysql字段中截取指定长度字符汉字代码