2

Hello i want to generate random string in php with repetition like Ag7hlA. is there anyway to do it i am trying this

<?php
function random_string($length)
{
    $length = (int) $length;
    if ($length < 1) return '';

    $base = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz123456789";
    $max = strlen($base) - 1;

    $string = '';    
    while ($len--)
    {
        $string = $base[mt_rand(0, $max)];
    }
    return $string;
}    
?>

But the random string is not being generated

4

1 回答 1

0
function generateRandomString($length = 10) {
    $char = 'abcdefghijklmnopqrstuvwxyz';
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $char[rand(0, strlen($char) - 1)];
    }
    return $randomString;
}

如果你也想加数字,那就是$char--->

$char = 'abcdefghijklmnopqrstuvwxyz1234567890';

如果资本案件--->

$char = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
于 2013-05-06T05:46:41.700 回答