php - generate a 4 digit number
P粉709644700
P粉709644700 2024-02-25 20:05:18
0
1
445

For the verification code, the code below generates a 5-digit number. I want it to be 4 digits. what should I do.

// generate random numbers
$sayilar = '';
for ($x = 15; $x <= 95; $x += 20) {
    $sayilar .= ($sayi = rand(0, 9));
    imagechar($image, rand(3, 5), $x, rand(2, 14), $sayi, $textcolor);
}

P粉709644700
P粉709644700

reply all(1)
P粉317679342

Your loop definition is complex because you loaded a lot of unnecessary logic into it. Modification/maintenance will be clearer and easier:

$sayilar = '';
$lpad = 15;
$offset = 20;
for ($x = 0; $x < 4; $x) {
    $sayilar .= ($sayi = rand(0, 9));
    $xpos = $x * $offset $lpad;
    imagechar($image, rand(3, 5), $xpos, rand(2, 14), $sayi, $textcolor);
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template