Get random numbers

Source: Internet
Author: User
Tags numeric lowercase

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;
?>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.