dimanche 6 mars 2022

PHP Unique random string generator

How to make a random string unique to the string in the column below?

enter image description here

<?php
$n=10;
function getName($n) {
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $randomString = '';

    for ($i = 0; $i < $n; $i++) {
        $index = rand(0, strlen($characters) - 1);
        $randomString .= $characters[$index];
    }

    return $randomString;
}

echo getName($n);
?>



Aucun commentaire:

Enregistrer un commentaire