Laravel zufällige Zeichenfolge
use Illuminate\Support\Str;
$random = Str::random(40);
Modern Marten
use Illuminate\Support\Str;
$random = Str::random(40);
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);
use Illuminate\Support\Str;
$randomString = Str::random(20);
function rand_str() {
$characters = '0123456789-=+{}[]:;@#~.?/>,<|\!"£$%^&*()abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randomstr = '';
for ($i = 0; $i < random_int(50, 100); $i++) {
$randomstr .= $characters[rand(0, strlen($characters) - 1)];
}
return $randomstr;
}
//select random value from array
use Illuminate\Support\Arr;
$array = [1, 2, 3, 4, 5];
$random = Arr::random($array);
//generate random string of specific length
use Illuminate\Support\Str;
$random = Str::random(40);