A function in PHP for generate Ramdom strings

charlygarcia120

Carlos Alberto

Posted on April 20, 2021

A function in PHP for generate Ramdom strings

If you need a function for generate ramdom strings, you can use this small fraction of code:

 <?php
<?php
    function generateRandomString($length = 10) {
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $charactersLength = strlen($characters);
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, $charactersLength - 1)];
    }
    return $randomString;
?>
Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
charlygarcia120
Carlos Alberto

Posted on April 20, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related