“PHP menghasilkan string karakter acak” Kode Jawaban

PHP menghasilkan string karakter acak

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);
Grepper

Menghasilkan string acak dalam php

phpCopy<?php 
$Random_str = uniqid();  
echo "Random String:", $Random_str, "\n";
?> 
CodeGuruDev

PHP generator string acak

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

Output the random string with the call below:

// Echo the random string.
// Optionally, you can give it a desired string length.
echo generateRandomString();
Ankur

Menghasilkan string acak dalam php

phpCopy<?php
 
echo "Out1: ",substr(md5(time()), 0, 16),"\n";
 
echo "Out2: ",substr(sha1(time()), 0, 16),"\n";
 
echo "Out3: ",md5(time()),"\n";
 
echo "Out4: ",sha1(time()),"\n";
 
?>
CodeGuruDev

Jawaban yang mirip dengan “PHP menghasilkan string karakter acak”

Pertanyaan yang mirip dengan “PHP menghasilkan string karakter acak”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya