laravel str :: aleatorio
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);
//generates 13 character random unique alphanumeric id
echo uniqid();
//output - 5e6d873a4f597
phpCopy<?php
$Random_str = uniqid();
echo "Random String:", $Random_str, "\n";
?>
function generateRandomString($digits) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randstring = '';
for ($i = 0; $i < $digits; $i++) {
$randstring .= $characters[rand(0, strlen($characters))];
}
return $randstring;
}
echo generateRandomString(24);
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;
}