Answers for "how do i make a random string in php"

PHP
28

PHP random string generator

function generateRandomString($length = 25) {
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $charactersLength = strlen($characters);
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, $charactersLength - 1)];
    }
    return $randomString;
}
//usage 
$myRandomString = generateRandomString(5);
Posted by: Guest on October-30-2019
0

Generate Random String in PHP

phpCopy<?php
 
echo "Output-1: ",bin2hex(random_bytes(10)),"\n";
 
echo "Output-2: ",bin2hex(random_bytes(20)),"\n";
 
echo "Output-3: ",bin2hex(random_bytes(24)),"\n";
 
?>
Posted by: Guest on April-23-2021

Code answers related to "how do i make a random string in php"

Browse Popular Code Answers by Language