Function: Get random string
Parameters:
1, (int) $length = #随机字符长度
2, (int) $mode = 0 #随机字符类型, 0 is uppercase and lowercase, 1 is numeric, 2 is small, 3 is uppercase, 4 is lowercase, 5 is uppercase and numeric, 6 is lowercase letters and numbers
Returns: the string obtained
<?php
Class Activecodeobj
{
function GetCode ($length = $mode = 0)
{
Switch ($mode) {
Case ' 1 ':
$str = ' 1234567890 ';
Break
Case ' 2 ':
$str = ' abcdefghijklmnopqrstuvwxyz ';
Break
Case ' 3 ':
$str = ' abcdefghijklmnopqrstuvwxyz ';
Break
Case ' 4 ':
$str = ' abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz ';
Break
Case ' 5 ':
$str = ' ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 ';
Break
Case ' 6 ':
$str = ' abcdefghijklmnopqrstuvwxyz1234567890 ';
Break
Default
$str = ' ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890 ';
Break
}
$result = ';
$l = strlen ($STR);
for ($i = 0; $i < $length; $i) {
$num = rand (0, $l);
$result. = $str [$num];
}
return $result;
}
}
?>
Instructions for use:
1. Save the code in the above box as random.php
2. Introduce random.php on the page you need
<?php incude (' random.php ');?>
3. Use the previously defined class
<?php
$code = new Activecodeobj;
$length = 32;
$mode = 0;
$str = $code->getcode ($length, $mode);
Echo $str;
?>